Can I get UAC prompt for user from batch file?

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...


I really love this solution from Anders.

@if (1==1) @if(1==0) @ELSE
@echo off&SETLOCAL ENABLEEXTENSIONS
>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);
@end

Should work flawlessly


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.


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).

JS:

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

var objShell = new ActiveXObject("shell.application");
// http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745.aspx
//                 Shell.ShellExecute method
// iRetVal = Shell.ShellExecute( sFile, [ vArguments ], [ vDirectory ], [ vOperation ], [ vShow ] )
objShell.ShellExecute("regimport.bat", curdir, "", "runas", 1); 

BAT:

cd /d %1

reg import env_set.reg
pause
reg import env_del.reg
pause 

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