Skip to content

Commit

Permalink
Use powershell to elevate and Fix setting and testing against errorle…
Browse files Browse the repository at this point in the history
…vels
  • Loading branch information
pal1000 committed May 6, 2020
1 parent fc46f9a commit 6460ccb
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions FWUpdate.bat
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
@echo off

:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
@cd /d "%~dp0"
@set "ERRORLEVEL="
@CMD /C EXIT 0
@"%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" >nul 2>&1
@if NOT "%ERRORLEVEL%"=="0" (
@powershell -Command Start-Process ""%0"" -Verb runAs 2>nul
@exit
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B

:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
set fwupdate=FWUpdLcl
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set fwupdate=%fwupdate%64
Expand Down

0 comments on commit 6460ccb

Please sign in to comment.