Skip to content

Commit ea790ad

Browse files
authored
Upgrade DeployWorkstation.bat to version 5.2
Updated the DeployWorkstation.bat script to version 5.2, enhancing error handling and ensuring proper execution of the PowerShell script.
1 parent e88d18f commit ea790ad

1 file changed

Lines changed: 22 additions & 34 deletions

File tree

DeployWorkstation.bat

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
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

104
echo.
11-
echo ===== DeployWorkstation Launcher v5.1 =====
5+
echo ===== DeployWorkstation Launcher v5.2 =====
126
echo.
137

148
REM --------------------------------------------------------
159
REM 1) Elevation check
16-
REM Re-launch this .bat elevated if not already admin.
1710
REM --------------------------------------------------------
1811
net 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

2821
echo [OK] Running as Administrator.
2922
echo.
3023

3124
REM --------------------------------------------------------
32-
REM 2) Change to the directory containing this .bat
25+
REM 2) Change to script directory
3326
REM --------------------------------------------------------
34-
pushd "%~dp0"
27+
pushd "%~dp0" || (
28+
echo [ERROR] Failed to access script folder.
29+
pause
30+
exit /b 1
31+
)
3532

3633
REM --------------------------------------------------------
37-
REM 3) Verify the PowerShell script is present
34+
REM 3) Verify PowerShell script exists
3835
REM --------------------------------------------------------
39-
if not exist "DeployWorkstation.ps1" (
36+
if not exist "%~dp0DeployWorkstation.ps1" (
4037
echo [ERROR] DeployWorkstation.ps1 not found.
4138
echo Expected: %~dp0DeployWorkstation.ps1
4239
echo.
@@ -56,7 +53,7 @@ echo 4. System configuration only
5653
echo 5. Exit
5754
echo.
5855
set "choice="
59-
set /p choice="Enter choice (1-5): "
56+
set /p "choice=Enter choice (1-5): "
6057

6158
set "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" (
8784
REM --------------------------------------------------------
8885
REM 5) Show what will run, then launch
8986
REM --------------------------------------------------------
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
)
9593
echo.
9694
echo Starting Windows PowerShell 5.1...
9795
echo.
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 "%~dp0DeployWorkstation.ps1" !ps_params!
10698
set "ps_exit=%errorlevel%"
10799

108100
REM --------------------------------------------------------
@@ -119,18 +111,14 @@ if "%ps_exit%"=="0" (
119111

120112
goto :normal_exit
121113

122-
REM --------------------------------------------------------
123114
:error_exit
124115
echo.
125116
echo ===== Launch aborted =====
126-
popd
127-
pause
128-
exit /b 1
117+
set "ps_exit=1"
129118

130-
REM --------------------------------------------------------
131119
:normal_exit
132120
popd
133121
echo.
134122
echo Press any key to close...
135123
pause >nul
136-
exit /b 0
124+
exit /b %ps_exit%

0 commit comments

Comments
 (0)