I'm writing a VBScript to check for UAC and, if found, run a second script in elevated manner. I have code as follows:
If (blnUACAvailable() AND blnUACEnabled()) Then 'Must be Vista or XP with UAC -- must elevate rights
objShell.ShellExecute strApp, strCommand, "", "RunAs", 1
objShell.ShellExecute strApp, strCommand, "", "", 1
This does a wonderful job of running using strApp to run strCommand in elevated manner (using RunAs), but the .ShellExecute call returns as soon as the command begins executing. I need my script to wait for this instance of strApp to fully close, before it continues along.
I've been exploring possibility of using properties in Win32_ProcessStartup to start strApp instead, but I'm not seeing a property I could set to get strApp to start in elevated manner.
For the non-elevated cases, I could use .Run, but that doesn't seem to have the option to elevate that .ShellExecute has... so doesn't seem to be want I need.
You can do this in PowerShell, but if you're looking for a way to do it in a WSH script or from a Cmd.exe shell script (also called a 'batch file') you can use my Elevate32/Elevate64 utility (x86 or x64 versions). Elevate32/Elevate64 works like Aaron Margosis' Elevate.js script, but it's a little better because it can wait for the elevated program to complete and get the elevated program's exit code. You can download it from my web site:
http://www.westmesatech.com/misctools.html (see ElevationToolkit1.zip)
For completeness, the Elevation Toolkit also contains IsElevated32/IsElevated64 that works like my IsAdmin.exe utility.