22REM ========================================================
33REM DeployWorkstation.bat
44REM Launcher for DeployWorkstation.ps1
5- REM Version 5.1 – PNWC Edition (fixed)
5+ REM Version 5.1 – PNWC Edition
66REM ========================================================
77
8- setlocal EnableExtensions EnableDelayedExpansion
8+ setlocal enabledelayedexpansion
99
1010echo .
1111echo ===== DeployWorkstation Launcher v5.1 =====
1212echo .
1313
1414REM --------------------------------------------------------
1515REM 1) Elevation check
16+ REM Re-launch this .bat elevated if not already admin.
1617REM --------------------------------------------------------
1718net session > nul 2 >& 1
18- if errorlevel 1 (
19+ if % errorlevel% neq 0 (
1920 echo Requesting administrative privileges...
2021 echo Please click " Yes" in the UAC prompt.
2122 echo .
22- powershell.exe -NoProfile -ExecutionPolicy Bypass - Command ^
23- " Start-Process -FilePath '%~f0 ' -Verb RunAs"
23+ powershell.exe -NoProfile -Command ^
24+ " Start-Process -FilePath '%~f0 ' -Verb RunAs -Wait "
2425 exit /b
2526)
2627
@@ -31,15 +32,11 @@ REM --------------------------------------------------------
3132REM 2) Change to the directory containing this .bat
3233REM --------------------------------------------------------
3334pushd " %~dp0 "
34- if errorlevel 1 (
35- echo [ERROR] Failed to access script folder.
36- goto :error_exit
37- )
3835
3936REM --------------------------------------------------------
4037REM 3) Verify the PowerShell script is present
4138REM --------------------------------------------------------
42- if not exist " %~dp0 DeployWorkstation .ps1" (
39+ if not exist " DeployWorkstation .ps1" (
4340 echo [ERROR] DeployWorkstation.ps1 not found.
4441 echo Expected: %~dp0 DeployWorkstation.ps1
4542 echo .
@@ -59,7 +56,7 @@ echo 4. System configuration only
5956echo 5. Exit
6057echo .
6158set " choice = "
62- set /p " choice = Enter choice (1-5): "
59+ set /p choice = " Enter choice (1-5): "
6360
6461set " ps_params = "
6562
@@ -79,7 +76,7 @@ if "%choice%"=="1" (
7976 echo [*] System configuration only.
8077 set " ps_params = -SkipBloatwareRemoval -SkipAppInstall"
8178) else if " %choice% " == " 5" (
82- set " ps_exit = 0 "
79+ echo Exiting.
8380 goto :normal_exit
8481) else (
8582 echo [!] Invalid choice - please try again.
@@ -90,18 +87,22 @@ if "%choice%"=="1" (
9087REM --------------------------------------------------------
9188REM 5) Show what will run, then launch
9289REM --------------------------------------------------------
93- if defined ps_params (
94- echo Parameters : !ps_params!
95- ) else (
90+ if " !ps_params! " == " " (
9691 echo Parameters : (none - full run)
92+ ) else (
93+ echo Parameters : !ps_params!
9794)
9895echo .
9996echo Starting Windows PowerShell 5.1...
10097echo .
10198
102- powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File " %~dp0 DeployWorkstation.ps1" !ps_params!
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+ )
103104
104- REM Capture exit code immediately
105+ REM Capture exit code immediately before anything can overwrite it
105106set " ps_exit = %errorlevel% "
106107
107108REM --------------------------------------------------------
@@ -122,12 +123,14 @@ REM --------------------------------------------------------
122123:error_exit
123124echo .
124125echo ===== Launch aborted =====
125- set " ps_exit = 1"
126+ popd
127+ pause
128+ exit /b 1
126129
127130REM --------------------------------------------------------
128131:normal_exit
129132popd
130133echo .
131134echo Press any key to close...
132135pause > nul
133- exit /b %ps_exit%
136+ exit /b 0
0 commit comments