Other Tips
Sponsored Link

Execute VBScript as admin privilege2012/12/21

  It's impossible to execute VBScript as admin privilege on Windows Vista or later because of UAC, so it's necessarry to elevate privileges first like follows.
For example, If Vista or later, elevate privileges first, if not, continue to execute.
Option Explicit

Dim WMI, OS, Value, Shell

do while WScript.Arguments.Count = 0 and WScript.Version >= 5.7
    '##### check windows version
    Set WMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set OS = WMI.ExecQuery("SELECT *FROM Win32_OperatingSystem")
    For Each Value in OS
    if left(Value.Version, 3) < 6.0 then exit do
    Next

    '##### execute as admin privileges
    Set Shell = CreateObject("Shell.Application")
    Shell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ uac", "", "runas"

    WScript.Quit
loop

'##### execute main processing
WScript.Echo "Hello World"

Matched Content