Elevate UAC / Admin rights for a batch file!
Posted in Operating Systems, Windows, Tools, Tips on Wednesday, January 16, 2013 by cam
A great tool for all system administrators!
@echo off :: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%system32cacls.exe" "%SYSTEMROOT%system32configsystem" 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" :-------------------------------------- <YOUR BATCH SCRIPT HERE>
Save the whole thing as install.bat
Now with WinRAR (yes go and install it), Right click install.bat and select “Add to archive…”
Under Archiving Options select: Create SFX archive
Click on the Comment tab (across the top)
Enter the following:
Path=%tmp% SavePath Setup=%tmp%install.bat Silent=1 Overwrite=1
If you want to add a pretty icon etc, thats done under the Advanced tab.
Click OK and your Done!
Now your practically unstoppable, Admin Rights and an executable file - Your life just got so much easier!
Link back for the WinRAR exe
Regards to this guy for BatchGotAdmin!