-1

Is it possible to have an AHK script instantly run as admin without me having to right-click on it? I would like to have the UAC prompt pop up when I double-click the script.

(Sorry if I am bad at explaining I am a beginner)

2 Answers2

1

You this snippet from the documentation to automatically relaunch any script as admin (if it already wasn't ran as admin).

full_command_line := DllCall("GetCommandLine", "str")

if (!(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
}

Just make sure this is in the auto-execute section (the top of the script).

0x464e
  • 5,948
  • 1
  • 12
  • 17
0

Create a shortcut to the AHK script (or to the compiled EXE that you made from it). In the properties for the shortcut, select the SHORTCUT tab, and click on the ADVANCED button. On the popup, put a check in the RUN AS ADMINISTRATOR box, then click OK, APPLY, OK

Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33