New
#1
Run as Administrator command name
Is there a command to insert into a batch file so the file can ask for administrator approval before continuing?
Is there a command to insert into a batch file so the file can ask for administrator approval before continuing?
Hello John,
I'm not sure about with a .bat file, but you could use this below with a .vbs file to have it prompt with UAC for elevation approval.
Hope this helps, :)Code:If WScript.Arguments.Count = 0 Then Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " Run", , "runas", 1 Else Your code here End If
Shawn
You can also create a Shortcut with Run as administrator to run the .bat file.
Yes there is a very easy way to have UAC ask for a batch file to prompt to run as admin:
See this code:
Code::: 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" :--------------------------------------