Tip of the Week: Force the UAC to prompt only once when a script runs

Blog Post created by andrew_audova on Jun 2, 2013

You may have run into cases where the User Account Control (UAC) prompts multiple times during the execution of a batch (.bat) script. With executables (.exe) and non-batch (.bat) file types you can right-click and select "Run as Administrator", to force the UAC to elevate the execution of the program. However, this approach doesn't work with batch scripts.


See below for a simple VBScript which can serve as a "wrapper" script, to force the UAC to prompt before running the intended batch script. This results in the entire script running with elevated permissions, which means no more additional UAC prompts. Just update the value of the filePath variable on the second line to point to the full path of the script, and save the file with a .vbs extension (VBScript). The script is now ready to run (just double-click it).



Dim filePath

filePath = "F:\installs\myScript.bat"


Set objShell = CreateObject("Shell.Application")

objShell.ShellExecute "cmd.exe", "/c " & filePath, "", "runas", 1