Add Run as Admin

Propose new features and changes
Posts: 27
Joined: 07 Jun 2017, 13:50

Add Run as Admin

20 Jun 2017, 09:29

Often times I need to run a script as admin. I have to do this manually since none of the options I've come across are viable.

Of course security is a big concern, so a password or some sort of security to prevent hacking is necessary, but it would help in a number of important cases to have that automatic ability.
User avatar
Posts: 79
Joined: 13 Jan 2015, 19:48

Re: Add Run as Admin

20 Jun 2017, 11:29

The Run documentation has this:
Try adding the following code at the top of your script:

Code: Select all

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

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"

MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%
Tested on XP/W7/W8.1/W10, works with both compiled and non-compiled scripts.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 3 guests