
"%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %* If '%1'='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)ĮCHO **************************************ĮCHO Invoking UAC for Privilege EscalationĮCHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"ĮCHO args = "ELEV " > "%vbsGetPrivileges%"ĮCHO For Each strArg in WScript.Arguments > "%vbsGetPrivileges%"ĮCHO args = args ^& strArg ^& " " > "%vbsGetPrivileges%"ĮCHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 > "%vbsGetPrivileges%"ĮCHO args = "/c """ + "!batchPath!" + """ " + args > "%vbsGetPrivileges%"ĮCHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 > "%vbsGetPrivileges%" If '%errorlevel%' = '0' ( goto gotPrivileges ) else ( goto getPrivileges ) Set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"

:: Automatically check & get admin rights

There is an easy way without the need to use an external tool - it runs fine with Windows 7, 8, 8.1 and 10 and is backwards-compatible too (Windows XP doesn't have any UAC, thus elevation is not needed - in that case the script just proceeds).Ĭheck out this code (I was inspired by the code by NIronwolf posted in the thread Batch File - "Access Denied" On Windows 7?), but I've improved it - in my version there isn't any directory created and removed to check for administrator privileges): ::::::::::::::::::::::::::::::::::::::::::::
