Skip to content

Instantly share code, notes, and snippets.

@Jaid
Last active March 19, 2021 04:14
Show Gist options
  • Select an option

  • Save Jaid/407c0f2b01aace1125ea34915ce1f6bb to your computer and use it in GitHub Desktop.

Select an option

Save Jaid/407c0f2b01aace1125ea34915ce1f6bb to your computer and use it in GitHub Desktop.
Force administrator permissions in AutoHotkey v2
; From https://gist.github.com/Jaid/407c0f2b01aace1125ea34915ce1f6bb
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
try {
if A_IsCompiled {
Run '*RunAs "' A_ScriptFullPath '" /restart'
} else {
Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
}
}
ExitApp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment