Skip to content

Commit 8406b5a

Browse files
committed
feat(bat): add debug mode and keep elevated window open for diagnosis
- Add ST_DEBUG flag and launcher log at %TEMP%\SystemTester_launcher.log - Pass debug flag across elevation; support -NoExit for PS in debug - Log key steps and PS command lines - Preserve working directory and window state
1 parent 4d76e6e commit 8406b5a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

SystemTester.bat

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ setlocal enableextensions enabledelayedexpansion
1111
set "MIN_ZIP_SIZE=10000000"
1212
set "DOWNLOAD_TIMEOUT_SEC=120"
1313
set "SCRIPT_VERSION=2.2"
14+
if not defined ST_DEBUG set "ST_DEBUG=0"
15+
set "LAUNCH_LOG=%TEMP%\SystemTester_launcher.log"
1416

1517
:: =====================================================
1618
:: Reliable admin detection and elevation
1719
:: =====================================================
1820
set "_ELEV_FLAG=%~1"
21+
set "_DEBUG_FLAG=%~2"
22+
if /i "%_DEBUG_FLAG%"=="debug" set "ST_DEBUG=1"
1923

2024
:: Primary admin check via PowerShell identity (works without Server service)
2125
set "IS_ADMIN="
@@ -49,7 +53,10 @@ echo.
4953
echo Requesting elevation...
5054
echo.
5155

52-
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -ArgumentList '/elevated' -Verb RunAs -WorkingDirectory '%CD%' -WindowStyle Normal"
56+
set "_ELEV_ARGS=/elevated"
57+
if "%ST_DEBUG%"=="1" set "_ELEV_ARGS=/elevated debug"
58+
echo [%DATE% %TIME%] Elevating: "%~f0" %_ELEV_ARGS% ^>^> "%LAUNCH_LOG%"
59+
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -ArgumentList '%_ELEV_ARGS%' -Verb RunAs -WorkingDirectory '%CD%' -WindowStyle Normal"
5360

5461
if errorlevel 1 (
5562
echo [ERROR] Failed to elevate. Run manually as administrator.
@@ -113,6 +120,9 @@ if "%SCRIPT_PS1%"=="" (
113120
)
114121

115122
echo Using PowerShell script: %SCRIPT_PS1_NAME%
123+
if "%ST_DEBUG%"=="1" (
124+
echo [%DATE% %TIME%] Using PS1: "%SCRIPT_PS1%" ^(exists: ^<^%SCRIPT_PS1%^^?^) >> "%LAUNCH_LOG%"
125+
)
116126
echo.
117127

118128
:: Check PowerShell version
@@ -180,7 +190,10 @@ echo STARTING INTERACTIVE MODE
180190
echo ========================================================
181191
echo.
182192
pause
183-
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PS1%"
193+
set "PS_EXTRA="
194+
if "%ST_DEBUG%"=="1" set "PS_EXTRA=-NoExit"
195+
if "%ST_DEBUG%"=="1" echo [%DATE% %TIME%] Launching PS interactive: powershell -NoProfile -ExecutionPolicy Bypass %PS_EXTRA% -File "%SCRIPT_PS1%" >> "%LAUNCH_LOG%"
196+
powershell -NoProfile -ExecutionPolicy Bypass %PS_EXTRA% -File "%SCRIPT_PS1%"
184197
echo.
185198
if errorlevel 1 (
186199
echo [ERROR] Script failed (code: %errorlevel%)
@@ -202,7 +215,10 @@ echo May take 10-30 minutes depending on your system.
202215
echo.
203216
pause
204217
echo.
205-
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PS1%" -AutoRun
218+
set "PS_EXTRA="
219+
if "%ST_DEBUG%"=="1" set "PS_EXTRA=-NoExit"
220+
if "%ST_DEBUG%"=="1" echo [%DATE% %TIME%] Launching PS autorun: powershell -NoProfile -ExecutionPolicy Bypass %PS_EXTRA% -File "%SCRIPT_PS1%" -AutoRun >> "%LAUNCH_LOG%"
221+
powershell -NoProfile -ExecutionPolicy Bypass %PS_EXTRA% -File "%SCRIPT_PS1%" -AutoRun
206222
echo.
207223
if errorlevel 1 (
208224
echo [ERROR] Tests failed (code: %errorlevel%)

0 commit comments

Comments
 (0)