texhex / BiosSledgehammer

Automated BIOS, ME, TPM firmware update and BIOS settings for HP devices
Apache License 2.0
127 stars 16 forks source link

Recommend to add in batch files that require admin rights #38

Closed dubl3a closed 6 years ago

dubl3a commented 6 years ago

I've been using this for a while (obtained from here: https://sites.google.com/site/eneerge/home/BatchGotAdmin) that automatically calls a UAC prompt and runs the batch as an admin:

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

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"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

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

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------
texhex commented 6 years ago

Thanks @dubl3a, but I do not think this is necessary. BIOS Sledgehammer should be run mostly automated, and in this case such a script is not necessary. Also, right-click "Run as Administrator" is build-in as well.