a136 does the "Run as Administrator" example work?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

a136 does the "Run as Administrator" example work?

Post by hpta » 28 May 2021, 04:40

here
https://lexikos.github.io/v2/docs/commands/Run.htm#RunAs

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

I guess it should open the UAC dialog when i click on the file containing this code - restarting the script as admin.
It does nothing for me. I remember this snippet was working in some of the previous versions, a122 I think.
Please could someone check this, whether it's working for them?

hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

Re: a136 does the "Run as Administrator" example work?

Post by hpta » 09 Jun 2021, 06:46

Ok, I figured it out. If I leave out

Code: Select all

        if A_IsCompiled
            Run '*RunAs "' A_ScriptFullPath '" /restart'
        else
in the try block, it works.
I guess something has changed with A_IsCompiled in a136.

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: a136 does the "Run as Administrator" example work?

Post by lexikos » 11 Jun 2021, 21:07

That's a bug. A_IsCompiled shouldn't be 1...

Post Reply

Return to “Ask for Help (v2)”