Skip to content

Commit 2705540

Browse files
committed
fix: streamline elevation process in Windows script for clarity
- Removed the option for automatic elevation, simplifying the user experience. - Updated messaging to clearly instruct users to run the script as Administrator. - Enhanced error handling by providing a specific exit code when not run with elevated privileges.
1 parent 1a67177 commit 2705540

File tree

1 file changed

+7
-36
lines changed
  • apps/portal/src/app/api/download-agent/scripts

1 file changed

+7
-36
lines changed

apps/portal/src/app/api/download-agent/scripts/windows.ts

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,16 @@ set "HAS_ERROR=0"
2727
set "ERRORS="
2828
set "EXIT_CODE=0"
2929
30-
REM Capture elevation flag if passed
31-
set "ELEVATED_FLAG=%~1"
32-
33-
REM Self-elevate if not running as administrator (check High Mandatory Level)
30+
REM Require Administrator (check High Mandatory Level) and exit with instructions if not elevated
3431
whoami /groups | find "S-1-16-12288" >nul 2>&1
35-
if errorlevel 1 if /I not "%ELEVATED_FLAG%"=="elevated" (
32+
if errorlevel 1 (
3633
color 0E
37-
echo Administrator permission is required.
38-
echo A prompt will appear asking for permission. Please click "Yes".
39-
echo If no prompt appears, right-click this file and select "Run as administrator".
34+
echo This script must be run as Administrator.
35+
echo Please right-click the file and select "Run as administrator".
4036
echo.
41-
echo Choose an option:
42-
echo [Y] Try to auto-elevate (recommended)
43-
echo [N] I will re-run manually as Administrator
44-
choice /C YN /N /M "Attempt automatic elevation? (Y/N): "
45-
if errorlevel 2 (
46-
echo.
47-
echo Please close this window and re-run the script by right-clicking it and selecting "Run as administrator".
48-
echo Press any key to exit.
49-
pause >nul
50-
exit /b
51-
) else (
52-
echo Elevating... A new window will open and remain open after running.
53-
rem Try PowerShell elevation first (keeps admin window open with /k)
54-
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/k','\"%~f0 elevated\"' -WorkingDirectory '%~dp0'" 2>nul
55-
rem Fallback to VBScript if PowerShell attempt failed or is blocked
56-
if not exist "%TEMP%\elevate.tmp" (
57-
> "%TEMP%\getadmin.vbs" echo Set UAC = CreateObject^("Shell.Application"^)
58-
>> "%TEMP%\getadmin.vbs" echo UAC.ShellExecute "%~f0", "elevated", "", "runas", 1
59-
wscript "%TEMP%\getadmin.vbs" >nul 2>&1
60-
del "%TEMP%\getadmin.vbs" >nul 2>&1
61-
)
62-
echo.
63-
echo This window will now stay open so you can see messages.
64-
echo Once the new admin window appears, you may close this one after confirming progress.
65-
echo Press any key to exit this non-admin window.
66-
pause >nul
67-
exit /b
68-
)
37+
echo Press any key to exit, then try again with Administrator privileges.
38+
pause
39+
exit /b 5
6940
)
7041
echo Running with administrator privileges.
7142
echo Current directory: %cd%

0 commit comments

Comments
 (0)