Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I get UAC prompt for user from batch file?

For example I need put some keys to registry under CurrentControlSet from batch file by

  reg import path\to\my.reg

PS. runas is not a solution as my customers uses different Windows localisation and I can not guess which name used for Administrator account (this can be Администратор)...

And script don't know administrator password.

And UAC dialog box does not require password entering...

share|improve this question
Have you tried the runas command? – Barend Oct 30 '11 at 14:16
I update answer in PS section... – gavenkoa Oct 30 '11 at 14:26
In that case you may have to ship an application manifest with your batch file, e.g. such as in the "Requesting elevation" section of this wikipedia article. – Barend Oct 30 '11 at 21:54
From Wikipedia: An assembly manifest is a text file containing metadata about .NET assemblies. Bat file does not use manifest... – gavenkoa Oct 30 '11 at 23:40

I really love this solution from Anders.

@if (1==1) @if(1==0) @ELSE
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"||(
    cscript //E:JScript //nologo "%~f0"
    @goto :EOF
reg import path\to\my.reg
@goto :EOF
@end @ELSE
ShA=new ActiveXObject("Shell.Application")
ShA.ShellExecute("cmd.exe","/c \""+WScript.ScriptFullName+"\"","","runas",5);

Should work flawlessly

share|improve this answer

Create a shortcut to reg.exe, give it the required arguments and set the "run as administrator" flag, then launch the shortcut from the batch file.

share|improve this answer
Finally I found solution. I can not create shortcut as script must perform action automatically... – gavenkoa Oct 30 '11 at 23:37
@gavenkoa: why would using a shortcut prevent the script from performing the action automatically? – Harry Johnston Feb 26 '13 at 18:27
OK, I firstly don't get your idea... It is easy to put shortcut into %TMP% dir... +1 – gavenkoa Feb 26 '13 at 21:25
up vote 1 down vote accepted

I automatically generate .js and .bat files. From .js call .bat so .bat can perform privileged actions (like adding values to registry as in example).


var fso = new ActiveXObject("Scripting.FileSystemObject");
var curdir = fso.GetParentFolderName(WScript.ScriptFullName);

var objShell = new ActiveXObject("shell.application");
//                 Shell.ShellExecute method
// iRetVal = Shell.ShellExecute( sFile, [ vArguments ], [ vDirectory ], [ vOperation ], [ vShow ] )
objShell.ShellExecute("regimport.bat", curdir, "", "runas", 1); 


cd /d %1

reg import env_set.reg
reg import env_del.reg

cd is essential as bat file start execution from %WINDIR%...

share|improve this answer
You can see practical example of this technique at – gavenkoa Nov 3 '11 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .