There are a lot of ways to skin that cat. One way, which I assume you're proposing, is to have a single script that goes through and executes the bulk of the processing, and it uses the
*RunAs verb to rerun itself with an elevated prompt when necessary. It's as good a way as any, and if you're doing it that way you would in fact not use
#SingleInstance, and you would pass additional parameters during the restarted version. The logic would probably look something like this completely untested pseudocode:
Code: Select all
WriteRegistry()
RestartExplorer()
; Other Work
ExitApp
WriteRegistry() {
if (A_IsAdmin) {
; Write the Registry Keys Here
if Instr(StrGet(DllCall("GetCommandLineW"), "UTF-16"), " -ELEVATED")
ExitApp
else
return
}
else if Instr(StrGet(DllCall("GetCommandLineW"), "UTF-16"), " -ELEVATED")
throw Exception("Can't acquire Admin Priveledges", -1)
else
RunWait % "*RunAs " StrGet(DllCall("GetCommandLineW"), "UTF-16") " -ELEVATED"
}
RestartExplorer() {
}
The secret sauce here is that you are using
DllCall to get the entire commandline (including AutoHotkey.exe), and passing it off using
RunWait to re-execute it.