Last active
May 21, 2016 16:13
-
-
Save waaaaRapy/10463764 to your computer and use it in GitHub Desktop.
sudo on windows using WScript.ShellExecute
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
Option Explicit | |
If WScript.Arguments.Count = 0 Then | |
WScript.Echo "Usage: sudo program [arg1 arg2 ...]" & vbCrLf & _ | |
"Run `program` with paramators as root in new console window" | |
Else | |
Dim ShellApp, WshShell | |
Dim cmd, varg, i | |
Set WshShell = CreateObject("WScript.Shell") | |
cmd = WshShell.ExpandEnvironmentStrings("%COMSPEC%") | |
'Build paramator | |
varg = "/C CD " & WshShell.CurrentDirectory & " & " | |
For i = 0 To WScript.Arguments.Count - 1 | |
varg = varg & " " & WScript.Arguments(i) | |
Next | |
varg = varg & " & PAUSE" | |
'run cmd /C ... as root | |
Set ShellApp = CreateObject("Shell.Application") | |
ShellApp.ShellExecute cmd, varg, "", "runas" | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment