- set-password.bat: one-time password setup -> writes webvnc.conf (HASH + VNC_PASSWORD), syncs UltraVNC via ensure-vnc-password.ps1; if the 'web-vnc' task is installed, restarts it (elevated) to reload the new password, skipping restart when the password is unchanged. - run.bat: no longer prompts for the password; reads it from webvnc.conf (asks to run set-password.bat first if absent). Also clears --spawn-command (not just --spawn) when 5900 is already listening, to avoid spawning a 2nd VNC server. - scripts/autostart-run.bat: non-interactive launcher for the scheduled task (reads webvnc.conf, finds only a LOCAL VNC server, never downloads at boot). - scripts/install-autostart.bat / uninstall-autostart.bat: register/remove a 'web-vnc' scheduled task (ONSTART, SYSTEM, HIGHEST) via schtasks. - scripts/restart-autostart.bat: restart the task to apply a new password; checks whether web-vnc.exe is running (stop+start, or just start). - .gitignore: ignore webvnc.conf (secret). - AGENTS.md / README.md: document the autostart flow, set-password.bat, the new scripts, and that the running gateway must be restarted to apply a password change.
129 lines
4.4 KiB
Batchfile
129 lines
4.4 KiB
Batchfile
@echo off
|
|
REM ============================================================
|
|
REM web-vnc launcher - starts the gateway without prompting.
|
|
REM The password is set up once with set-password.bat (stored in
|
|
REM webvnc.conf). If webvnc.conf is missing, this script tells you
|
|
REM to run set-password.bat first.
|
|
REM ============================================================
|
|
cd /d "%~dp0"
|
|
|
|
echo.
|
|
echo === web-vnc: VNC in the browser ===
|
|
echo.
|
|
|
|
REM --- 1. Binary ---
|
|
if exist "web-vnc.exe" goto havebin
|
|
where go >nul 2>nul
|
|
if not errorlevel 1 goto dogobuild
|
|
echo [error] web-vnc.exe not found and Go is not installed.
|
|
echo Install Go from https://go.dev/dl/ or place a built web-vnc.exe next to this script.
|
|
echo.
|
|
pause
|
|
exit /b 1
|
|
:dogobuild
|
|
echo Building web-vnc.exe ...
|
|
go build -o web-vnc.exe .\cmd\web-vnc
|
|
if errorlevel 1 goto buildfail
|
|
:havebin
|
|
|
|
REM --- 2. noVNC client ---
|
|
if exist "internal\server\static\core\rfb.js" goto havenovnc
|
|
echo noVNC client is not bundled yet. Trying to download ...
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-novnc.ps1"
|
|
if errorlevel 1 goto novncfail
|
|
echo Rebuilding with noVNC ...
|
|
go build -o web-vnc.exe .\cmd\web-vnc
|
|
goto havenovnc
|
|
:novncfail
|
|
echo [warning] Could not download noVNC (no internet?).
|
|
echo The browser will open a page with a hint. Retry later: scripts\get-novnc.ps1
|
|
echo.
|
|
:havenovnc
|
|
|
|
REM --- 3. VNC server (find/download) ---
|
|
set "SPAWNARGS="
|
|
set "SPAWN_CMD="
|
|
if exist "vnc\winvnc.exe" goto uselocalvnc
|
|
if exist "vnc\tvnserver.exe" goto uselocalvnc
|
|
if exist "C:\Program Files\UltraVNC\winvnc.exe" goto autodetectvnc
|
|
if exist "C:\Program Files (x86)\UltraVNC\winvnc.exe" goto autodetectvnc
|
|
if exist "C:\Program Files\uvnc bvba\UltraVNC\winvnc.exe" goto autodetectvnc
|
|
if exist "C:\Program Files (x86)\uvnc bvba\UltraVNC\winvnc.exe" goto autodetectvnc
|
|
if exist "C:\Program Files\TightVNC\tvnserver.exe" goto autodetectvnc
|
|
if exist "C:\Program Files (x86)\TightVNC\tvnserver.exe" goto autodetectvnc
|
|
echo VNC server not found. Trying to download a portable UltraVNC ...
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\get-vnc.ps1"
|
|
if errorlevel 1 goto novncserver
|
|
if exist "vnc\winvnc.exe" goto uselocalvnc
|
|
if exist "vnc\tvnserver.exe" goto uselocalvnc
|
|
goto novncserver
|
|
:uselocalvnc
|
|
if exist "vnc\winvnc.exe" set "SPAWN_CMD=vnc\winvnc.exe -run"
|
|
if exist "vnc\tvnserver.exe" if not defined SPAWN_CMD set "SPAWN_CMD=vnc\tvnserver.exe -run"
|
|
set "SPAWNARGS=--spawn-command "%SPAWN_CMD%""
|
|
echo Found local VNC server: %SPAWN_CMD%
|
|
goto vncdone
|
|
:autodetectvnc
|
|
echo VNC server found in the system (auto-detection on start).
|
|
goto vncdone
|
|
:novncserver
|
|
echo [warning] Could not get a VNC server.
|
|
echo Without a VNC server the desktop will not be streamed.
|
|
echo Install UltraVNC/TightVNC manually or retry: scripts\get-vnc.ps1
|
|
echo.
|
|
:vncdone
|
|
|
|
REM --- 4. Stored password (set up once via set-password.bat) ---
|
|
if not exist "webvnc.conf" goto nopwconf
|
|
set "HASH="
|
|
set "VNC_PW="
|
|
for /f "tokens=1,* delims==" %%a in (webvnc.conf) do (
|
|
if /i "%%a"=="HASH" set "HASH=%%b"
|
|
if /i "%%a"=="VNC_PASSWORD" set "VNC_PW=%%b"
|
|
)
|
|
if "%HASH%"=="" goto nopwconf
|
|
if "%VNC_PW%"=="" goto nopwconf
|
|
REM The same password is auto-sent to noVNC to authenticate against the VNC server.
|
|
set "WEBVNC_VNC_PASSWORD=%VNC_PW%"
|
|
set "VNC_PW="
|
|
goto havepw
|
|
:nopwconf
|
|
echo [error] Password is not configured yet.
|
|
echo Run set-password.bat once to set the password, then start run.bat.
|
|
echo.
|
|
pause
|
|
exit /b 1
|
|
:havepw
|
|
|
|
REM --- 5. Available addresses ---
|
|
echo.
|
|
echo === Addresses to connect to (port 8080) ===
|
|
echo http://localhost:8080
|
|
for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\list-ips.ps1"') do echo http://%%a:8080
|
|
echo.
|
|
echo If it does not open from another machine, run once as administrator:
|
|
echo scripts\open-firewall.bat
|
|
echo.
|
|
|
|
REM --- 6. Launch ---
|
|
echo Starting web-vnc on http://localhost:8080
|
|
echo Stop: Ctrl+C
|
|
echo.
|
|
REM --- 6b. 5900 already listening? -> do NOT spawn a 2nd VNC server (avoid conflict with the UltraVNC service) ---
|
|
set "SPAWNFLAG=--spawn"
|
|
powershell -NoProfile -Command "try{$c=New-Object Net.Sockets.TcpClient('127.0.0.1',5900);$c.Close();exit 0}catch{exit 1}"
|
|
if not errorlevel 1 (
|
|
echo VNC server already listening on 127.0.0.1:5900 - connecting to it without --spawn.
|
|
set "SPAWNFLAG="
|
|
set "SPAWNARGS="
|
|
)
|
|
web-vnc.exe --password-hash "%HASH%" %SPAWNARGS% %SPAWNFLAG% --listen :8080
|
|
echo.
|
|
echo Server stopped.
|
|
pause
|
|
exit /b
|
|
|
|
:buildfail
|
|
echo Build failed.
|
|
pause
|
|
exit /b 1 |