Created
January 6, 2021 16:23
-
-
Save codeartery/f9fa041933773628ddc9e60b67dfef20 to your computer and use it in GitHub Desktop.
Will run the current VBScript as an administrator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM:<RunAsAdmin> | |
' Place this code at the top of your VBScript file to run the script as an admin. | |
' It will quit the current script and re-run the script as an administrator. | |
' Note that depending on your UAC permissions you may be prompted. | |
' Does not support command line arguments. | |
If Not WScript.Arguments.Named.Exists("AsAdmin") Then | |
CreateObject("Shell.Application").ShellExecute "WScript.exe", """" & WScript.ScriptFullName & """ /AsAdmin", "", "runas", 1 | |
WScript.Quit | |
End If | |
REM:</RunAsAdmin> | |
' Your code here... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM:<RunAsAdmin> | |
If Not WScript.Arguments.Named.Exists("AsAdmin") Then | |
CreateObject("Shell.Application").ShellExecute "WScript.exe", """" & WScript.ScriptFullName & """ /AsAdmin", "", "runas", 1 | |
WScript.Quit | |
End If | |
REM:</RunAsAdmin> | |
' Example code that needs admin permissions to run. | |
Dim oWss: Set oWss = CreateObject("WScript.Shell") | |
Call oWss.Run("cmd /k net user administrator /active:yes") | |
' Call oWss.Run("cmd /k net user administrator /active:no") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment