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 ? "shell32ShellExecute":"shell32ShellExecuteA"
    
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
}
原文地址:https://www.cnblogs.com/cnsealine/p/3339812.html