AHK Run as Administrator In AHK
Ⅰ:Just put this script to your Standard Library and put this function at the top of the script, as simple as that.
RunAsAdmin()
Download : RunAsAdmin.ahk
Ⅱ:To run for any scripts, compiled or not, with params use this code instead..
Loop, %0% ; For each parameter: { param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index. params .= A_Space . param } ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA" if not A_IsAdmin { If A_IsCompiled DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1) Else DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1) ExitApp }