'========================================================================= ' ElevateWscript.vbs ' VERSION: 1.0 ' AUTHOR: Brian Steinmeyer ' EMAIL: sigkill@sigkillit.com ' WEB: http://sigkillit.com ' DATE: 1/25/2012 ' COMPATIBLE: Windows Vista, Server 2008, and Above ' COMMENTS: Since the introduction of UAC in Windows, despite being an ' administrator you may still need to run a script with elevated ' privileges. For example the CommandLine property of the WIN32_Process class ' requires a script to be elevated in order to return valid data when the process ' is running as another user. Unfortunately, Windows does not provide Run As ' Administrator on the context of a .vbs file, which is why I made this. ' To use the script, pass the full path to a .vbs file to the Sub and it ' will prompt you to run the script elevated. If the script you need to elevate ' in located in the same directory as this script, you can just pass the script ' name. Alternatively, you can always launch your vbscript from an elevated ' command prompt which will use wscript or cscript elevated as well. ' EXAMPLE: Elevate a script using the full path ' Call ElevateWscript("C:\scripts\test.vbs") ' EXAMPLE: Elevate a script in the same directory as ElevateWscript.vbs ' Call ElevateWscript("test.vbs") '========================================================================= Option Explicit Call ElevateWscript("test.vbs") Private Sub ElevateWscript(scriptName) Dim objShell: Set objShell = CreateObject("Shell.Application") Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(scriptName) Then Dim objFile: Set objFile = objFSO.GetFile(scriptName) objShell.ShellExecute "wscript.exe", Chr(34) & objFile.Path & Chr(34), "", "runas", 1 Else Wscript.Echo "Script Does Not Exist!" & vbCrLf & scriptName End If End Sub