11@ echo off
2- REM ========================================================
3- REM DeployWorkstation.bat
4- REM Launcher for DeployWorkstation.ps1
5- REM Version 5.1 – PNWC Edition
6- REM ========================================================
7-
8- setlocal enabledelayedexpansion
2+ setlocal EnableExtensions EnableDelayedExpansion
93
104echo .
11- echo ===== DeployWorkstation Launcher v5.1 =====
5+ echo ===== DeployWorkstation Launcher v5.2 =====
126echo .
137
148REM --------------------------------------------------------
159REM 1) Elevation check
16- REM Re-launch this .bat elevated if not already admin.
1710REM --------------------------------------------------------
1811net session > nul 2 >& 1
19- if % errorlevel% neq 0 (
12+ if errorlevel 1 (
2013 echo Requesting administrative privileges...
2114 echo Please click " Yes" in the UAC prompt.
2215 echo .
23- powershell.exe -NoProfile -Command ^
24- " Start-Process -FilePath '%~f0 ' -Verb RunAs -Wait "
16+ powershell.exe -NoProfile -ExecutionPolicy Bypass - Command ^
17+ " Start-Process -FilePath '%~f0 ' -Verb RunAs"
2518 exit /b
2619)
2720
2821echo [OK] Running as Administrator.
2922echo .
3023
3124REM --------------------------------------------------------
32- REM 2) Change to the directory containing this .bat
25+ REM 2) Change to script directory
3326REM --------------------------------------------------------
34- pushd " %~dp0 "
27+ pushd " %~dp0 " || (
28+ echo [ERROR] Failed to access script folder.
29+ pause
30+ exit /b 1
31+ )
3532
3633REM --------------------------------------------------------
37- REM 3) Verify the PowerShell script is present
34+ REM 3) Verify PowerShell script exists
3835REM --------------------------------------------------------
39- if not exist " DeployWorkstation .ps1" (
36+ if not exist " %~dp0 DeployWorkstation .ps1" (
4037 echo [ERROR] DeployWorkstation.ps1 not found.
4138 echo Expected: %~dp0 DeployWorkstation.ps1
4239 echo .
@@ -56,7 +53,7 @@ echo 4. System configuration only
5653echo 5. Exit
5754echo .
5855set " choice = "
59- set /p choice = " Enter choice (1-5): "
56+ set /p " choice = Enter choice (1-5): "
6057
6158set " ps_params = "
6259
@@ -76,7 +73,7 @@ if "%choice%"=="1" (
7673 echo [*] System configuration only.
7774 set " ps_params = -SkipBloatwareRemoval -SkipAppInstall"
7875) else if " %choice% " == " 5" (
79- echo Exiting.
76+ set " ps_exit = 0 "
8077 goto :normal_exit
8178) else (
8279 echo [!] Invalid choice - please try again.
@@ -87,22 +84,17 @@ if "%choice%"=="1" (
8784REM --------------------------------------------------------
8885REM 5) Show what will run, then launch
8986REM --------------------------------------------------------
90- if " !ps_params! " == " " (
91- echo Parameters : (none - full run)
92- ) else (
87+ echo .
88+ if defined ps_params (
9389 echo Parameters : !ps_params!
90+ ) else (
91+ echo Parameters : (none - full run)
9492)
9593echo .
9694echo Starting Windows PowerShell 5.1...
9795echo .
9896
99- if " !ps_params! " == " " (
100- powershell.exe -NoProfile -ExecutionPolicy Bypass -File " DeployWorkstation.ps1"
101- ) else (
102- powershell.exe -NoProfile -ExecutionPolicy Bypass -File " DeployWorkstation.ps1" !ps_params!
103- )
104-
105- REM Capture exit code immediately before anything can overwrite it
97+ powershell.exe -NoProfile -ExecutionPolicy Bypass -File " %~dp0 DeployWorkstation.ps1" !ps_params!
10698set " ps_exit = %errorlevel% "
10799
108100REM --------------------------------------------------------
@@ -119,18 +111,14 @@ if "%ps_exit%"=="0" (
119111
120112goto :normal_exit
121113
122- REM --------------------------------------------------------
123114:error_exit
124115echo .
125116echo ===== Launch aborted =====
126- popd
127- pause
128- exit /b 1
117+ set " ps_exit = 1"
129118
130- REM --------------------------------------------------------
131119:normal_exit
132120popd
133121echo .
134122echo Press any key to close...
135123pause > nul
136- exit /b 0
124+ exit /b %ps_exit%
0 commit comments