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.
Add Run as Admin
-
- Posts: 27
- Joined: 07 Jun 2017, 13:50
Re: Add Run as Admin
The Run documentation has this: https://autohotkey.com/docs/commands/Run.htm#RunAs
Try adding the following code at the top of your script:Tested on XP/W7/W8.1/W10, works with both compiled and non-compiled scripts.
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)"))
{
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%
YOU'RE NOT ALEXANDER
Re: Add Run as Admin
What isn't viable about RunAsTask?
Who is online
Users browsing this forum: No registered users and 35 guests