Created
March 18, 2020 12:19
-
-
Save Artoria2e5/0cfc88ba98e48a643b1d92568491e368 to your computer and use it in GitHub Desktop.
Proxy script for running anything as an admin. Contains an CommandLineToArgvW escaper.
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
' Proxy script for running anything as an admin. In this case, AHK. | |
Set UAC = CreateObject("Shell.Application") | |
Dim Arguments | |
' Build arguments | |
Arguments = "" | |
For Each strArg in WScript.Arguments | |
Arguments = Arguments & Escape(strArg) & " " | |
Next | |
UAC.ShellExecute "C:\Program Files\AutoHotkey\AutoHotkey.exe", Arguments, "", "runas", 1 | |
' Escape per CommandLineToArgv. | |
' See https://github.com/Artoria2e5/node/blob/fix!/child-process-args/doc/api/child_process.md#windows-command-line | |
' See https://github.com/nodejs/node/pull/29576 | |
Function Escape(Arg) | |
' js: return `"${arg.replace(/(\\*)($|")/g, '$1$1$2').replace(/"/g, '""')}"`; | |
Dim tmp | |
Set sub1 = New RegExp | |
sub1.Global = True | |
sub1.pattern = "(\\*)($|"")" | |
tmp = sub1.Replace(Arg, "$1$1$2") | |
Set sub2 = New RegExp | |
sub2.Global = True | |
sub2.pattern = Chr(34) | |
tmp = sub2.Replace(tmp, Chr(34) & Chr(34)) | |
Escape = Chr(34) & tmp & Chr(34) | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment