Repository navigation
Expand file tree
/
Copy pathdeploy_network.bat
More file actions
136 lines (124 loc) · 4.45 KB
/
Copy pathdeploy_network.bat
File metadata and controls
136 lines (124 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@echo off
setlocal enabledelayedexpansion
title PC Remote Sentinel - Network Fleet Deployer
cd /d "%~dp0"
echo ==============================================================
echo PC REMOTE SENTINEL - NETWORK FLEET DEPLOYER
echo ==============================================================
echo.
echo Starting the network deployment server...
echo This will let you deploy to all PCs over WiFi.
echo.
:: Auto-elevate to admin (needed for firewall rules)
net session >nul 2>&1
if %errorlevel% neq 0 (
if "%~1"=="--no-elevate" (
echo [!] Running without administrator privileges.
echo [Windows firewall may prompt to allow network access]
) else (
echo [!] Requesting Administrator privileges for firewall rules...
set "TARGET_BAT=%~f0"
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process cmd.exe -ArgumentList @('/k', 'call', ('\"' + $env:TARGET_BAT + '\"'), '--elevated') -Verb RunAs" 2>nul
if !errorlevel! equ 0 exit /b
echo [!] Elevation bypassed. Continuing in current window...
)
)
:: Find working Python - try multiple reliable methods
set "PY_CMD="
:: Method 1: Direct python command execution check
for /f "delims=" %%i in ('python -c "import sys; print(sys.executable)" 2^>nul') do (
set "CANDIDATE=%%i"
if exist "!CANDIDATE!" (
echo !CANDIDATE! | findstr /i "WindowsApps" >nul 2>&1
if errorlevel 1 (
set "PY_CMD=!CANDIDATE!"
)
)
)
if defined PY_CMD goto :py_found
:: Method 2: Check py launcher
if not defined PY_CMD (
for /f "delims=" %%i in ('py -3 -c "import sys; print(sys.executable)" 2^>nul') do (
set "CANDIDATE=%%i"
if exist "!CANDIDATE!" (
set "PY_CMD=!CANDIDATE!"
)
)
)
if defined PY_CMD goto :py_found
:: Method 3: Check standard Python install directories
if not defined PY_CMD (
for %%p in (
"C:\Program Files\Python314\python.exe"
"C:\Program Files\Python313\python.exe"
"C:\Program Files\Python312\python.exe"
"C:\Program Files\Python311\python.exe"
"C:\Program Files\Python310\python.exe"
"C:\Python314\python.exe"
"C:\Python313\python.exe"
"C:\Python312\python.exe"
"C:\Python311\python.exe"
"C:\Python310\python.exe"
"%LOCALAPPDATA%\Programs\Python\Python314\python.exe"
"%LOCALAPPDATA%\Programs\Python\Python313\python.exe"
"%LOCALAPPDATA%\Programs\Python\Python312\python.exe"
"%LOCALAPPDATA%\Programs\Python\Python311\python.exe"
"%LOCALAPPDATA%\Programs\Python\Python310\python.exe"
) do (
if not defined PY_CMD (
if exist %%p (
%%p -c "import sys" >nul 2>&1
if !errorlevel! equ 0 (
set "PY_CMD=%%~p"
)
)
)
)
)
if defined PY_CMD goto :py_found
:: Method 4: PowerShell command query
if not defined PY_CMD (
for /f "delims=" %%i in ('powershell -NoProfile -Command "(Get-Command python -ErrorAction SilentlyContinue).Source" 2^>nul') do (
set "CANDIDATE=%%i"
if exist "!CANDIDATE!" (
echo !CANDIDATE! | findstr /i "WindowsApps" >nul 2>&1
if errorlevel 1 (
set "PY_CMD=!CANDIDATE!"
)
)
)
)
if defined PY_CMD goto :py_found
:: Method 5: Windows Registry lookup
if not defined PY_CMD (
for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Python\PythonCore" /s /v ExecutablePath 2^>nul ^| findstr /i "ExecutablePath"') do (
if not defined PY_CMD (
if exist "%%b" set "PY_CMD=%%b"
)
)
for /f "tokens=2*" %%a in ('reg query "HKCU\SOFTWARE\Python\PythonCore" /s /v ExecutablePath 2^>nul ^| findstr /i "ExecutablePath"') do (
if not defined PY_CMD (
if exist "%%b" set "PY_CMD=%%b"
)
)
)
if defined PY_CMD goto :py_found
:: If all methods failed
echo.
echo [X] Python not found! Please install Python first.
echo Download from: https://www.python.org/downloads/
echo.
pause
exit /b 1
:py_found
echo [OK] Using Python: %PY_CMD%
echo.
:: Allow deployer through firewall (if running as admin)
net session >nul 2>&1
if %errorlevel% equ 0 (
netsh advfirewall firewall delete rule name="PCSentinelDeployer" >nul 2>&1
netsh advfirewall firewall add rule name="PCSentinelDeployer" dir=in action=allow protocol=TCP localport=9090 enable=yes profile=any >nul 2>&1
)
:: Run the deployer
"%PY_CMD%" "%~dp0network_deployer.py"
pause