0
点赞
收藏
分享

微信扫一扫

[FUNC]管理员权限运行两法


管理员权限运行

RunAsAdmin() {
  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
  }
}

Elevate(func, prms*)
{
    cmd := func
    for i,prm in prms
    {
        StringReplace prm, prm, `", "", All
        cmd .= " """ prm """"
    }
    if A_IsCompiled
        exe := A_ScriptFullPath
    else
        exe := A_AhkPath, cmd := """" A_ScriptFullPath """ " cmd
    return DllCall("shell32\ShellExecute", "ptr", 0, "str", "RunAs"
                    , "str", exe, "str", cmd, "ptr", 0, "int", 1) > 32
}




举报

相关推荐

0 条评论