refactor: move user-facing scripts to repo root; fix set-password ordering

- install-autostart.bat, uninstall-autostart.bat, restart-autostart.bat,
  open-firewall.bat moved from scripts/ to the repo root (next to run.bat and
  set-password.bat). Internal helpers (autostart-run.bat, ensure-vnc-password.ps1,
  get-novnc.*, get-vnc.ps1, list-ips.ps1) stay in scripts/. autostart-run.bat is
  kept in scripts/ because the scheduled task /TR points at it; moving it would
  break already-installed tasks.
- Updated all references (set-password.bat, run.bat, install/restart-autostart.bat,
  AGENTS.md, README.md).
- set-password.bat: write webvnc.conf BEFORE the UltraVNC sync so the web password
  is configured even if ensure-vnc-password.ps1 fails / its UAC is dismissed
  (previously 'Password is not configured' from install-autostart.bat when the
  sync blocked before conf was written).
- AGENTS.md / README.md structure + autostart sections updated for the new layout.
This commit is contained in:
Codex
2026-08-05 15:38:39 +03:00
parent 754f77a8d0
commit 9b8ee94dd5
8 changed files with 64 additions and 50 deletions
+20 -17
View File
@@ -1,16 +1,17 @@
@echo off
REM ============================================================
REM set-password.bat - setup of the web access password.
REM Asks for the password, syncs the UltraVNC service password,
REM generates a hash and saves both to webvnc.conf (gitignored).
REM After this, run.bat and the autostart task start without asking.
REM Asks for the password, generates a hash and saves it together
REM with the VNC password to webvnc.conf (gitignored). AFTER that
REM (so the web password is configured even if the next step fails)
REM it syncs the UltraVNC service password via ensure-vnc-password.ps1.
REM
REM If the "web-vnc" autostart task is installed, this script also
REM restarts it (elevated, via scripts\restart-autostart.bat) so the
REM restarts it (elevated, via restart-autostart.bat) so the
REM running gateway reloads the new password. The restart is skipped
REM only when the password did not actually change (the running gateway
REM already accepts it). restart-autostart.bat checks whether
REM web-vnc.exe is running and stops+starts it, or just starts it.
REM only when the password did not actually change. restart-autostart.bat
REM checks whether web-vnc.exe is running and stops+starts it, or just
REM starts it.
REM ============================================================
cd /d "%~dp0"
@@ -52,12 +53,7 @@ if "%PW%"=="" (
goto getpw
)
REM --- 4. Sync UltraVNC service password (UAC only if it differs) ---
echo Syncing UltraVNC password with the one entered ...
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\ensure-vnc-password.ps1" -Password "%PW%"
if errorlevel 1 echo [warning] Could not sync the UltraVNC password - continuing.
REM --- 5. Generate hash ---
REM --- 4. Generate hash ---
echo Generating password hash ...
set "HASH="
for /f "delims=" %%i in ('web-vnc.exe --gen-hash "%PW%"') do set "HASH=%%i"
@@ -67,12 +63,19 @@ if "%HASH%"=="" (
exit /b 1
)
REM --- 6. Save to webvnc.conf (overwrite) ---
REM --- 5. Save to webvnc.conf (overwrite) ---
REM Done BEFORE the UltraVNC sync so the web password is configured
REM even if the sync below fails or is cancelled (UAC).
echo HASH=%HASH%> "webvnc.conf"
echo VNC_PASSWORD=%PW%>> "webvnc.conf"
set "HASH="
echo Saved to webvnc.conf.
REM --- 6. Sync UltraVNC service password (UAC only if it differs) ---
echo Syncing UltraVNC password with the one entered ...
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\ensure-vnc-password.ps1" -Password "%PW%"
if errorlevel 1 echo [warning] Could not sync the UltraVNC password - the web password is still saved.
REM --- 7. Apply to the running gateway (if the autostart task is installed) ---
REM web-vnc.exe reads the hash + VNC password only at startup, so a
REM restart is required for the new password to take effect.
@@ -86,20 +89,20 @@ if not defined OLD_PW goto do_restart
if /i not "%OLD_PW%"=="%PW%" goto do_restart
echo.
echo Password unchanged - the running gateway keeps accepting it. No restart needed.
echo If the gateway is not running, start it with: scripts\restart-autostart.bat ^(admin^)
echo If the gateway is not running, start it with: restart-autostart.bat ^(admin^)
goto cleanup
:do_restart
echo.
echo Applying the new password to the "web-vnc" task ^(needs admin^) ...
powershell -NoProfile -Command "Start-Process -FilePath '%~dp0scripts\restart-autostart.bat' -Verb RunAs -Wait"
powershell -NoProfile -Command "Start-Process -FilePath '%~dp0restart-autostart.bat' -Verb RunAs -Wait"
goto cleanup
:no_task
echo.
echo Autostart task "web-vnc" is not installed.
echo To start on every boot, run once as administrator:
echo scripts\install-autostart.bat
echo install-autostart.bat
:cleanup
set "PW="