RunAs - explaining example from the docs

Get help with using AutoHotkey and its commands and hotkeys
Posts: 175
Joined: 05 May 2017, 13:19

RunAs - explaining example from the docs

20 Jul 2018, 17:01

Here is an example from the docs. I'm trying to understand what RegExMatch(full_command_line, " /restart(?!\S)") is doing. I tested this code and it seems we could simply remove RegExMatch part without any difference in the behaviour. But probably I miss something?

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%
Last edited by john_c on 20 Jul 2018, 17:21, edited 1 time in total.
User avatar
Posts: 1834
Joined: 30 Sep 2013, 06:48

Re: RunAs - explaining example from the docs

20 Jul 2018, 17:13
If UAC is disabled, *RunAs will launch the process without elevating it. Checking for /restart in the command line ensures that the script does not enter a runaway loop in that case.
As I understand it, it prevents an endless re-start loop, if the restart with elevated rights failed (because of disabled UAC) the first time (if it was restarted by this snippet, the /restart string will appear in the command line, compare the RunAs lines). If it could not fail, it could probably be left out.

Ps.: Would be cool next time, if you could directly link to the doc page where you took it from.

Return to “Ask For Help”

Who is online

Users browsing this forum: Rohwedder, tonkomnom and 30 guests