Run as Administrator using ShellExecute
Running scripts that require administrative privileges is a common challenge in Windows Scripting. The current post aims to detail the different implementations of process elevation using the ShellExecute method of the Shell Automation Service COM object in WSH scripts, PowerShell and .NET. 1. Process Elevation with ShellExecute The snippet below shows the RunAsAdministrator subroutine (VBScript) and function (JScript). It takes two inputs: an absolute or relative file path and additional command line arguments joined in a string. Be aware that the file type is not always an executable. It may be any file type as long as there is a registered association with an executable on the system. The snippets and examples will be limited to .exe files only. /** * @param {string} programExe - the path to the program to elevate * @param {string} command - the arguments used to run the program */ function RunAsAdministrator(programExe, command) { var Shell32 = new ActiveXObject('...