DllCall - trouble with 'StrGet(DllCall("GetCommandLine", "ptr")'

Issue #81 closed
Winter Laite created an issue

Code works in AHK v2.0-beta.9 and Keysharp, but different messages are returned.

full_command_line := StrGet(DllCall("GetCommandLine", "ptr"))

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 )

From AHK:

A_IsAdmin: 1
Command line: "C:\Program Files\AutoHotkey\v2.0-beta.9\AutoHotkey64_UIA.exe" "C:\Users\tester\Documents\repos\keysharp\bin\debug\net6.0-windows\runas3.ahk"

From Keysharp:

A_IsAdmin: 1
Command line: keysharp  runas3.ahk

As you can see, with Keysharp the full program path of the command line is not reported, and is not enclosed in quotes.

Running the same code with AHK and a dummy argument “cheesecake” produces this:

A_IsAdmin: 1
Command line: "C:\Program Files\AutoHotkey\v2.0-beta.9\AutoHotkey64_UIA.exe" "C:\Users\tester\Documents\repos\keysharp\bin\debug\net6.0-windows\runas3.ahk" cheesecake

Here there are three components: 1) the full path of the program itself, i.e. AutoHotkey in quotes; 2) the full path of the target script, in quotes; and 3) the argument passed to the target script, here cheesecake with no quotes.

The same script run as follows, i.e. ‘keysharp runas3.ahk cheesecake’ simply exits. The MsgBox is never shown.

(It’s important to note that the command is not being run, but merely reported, which is why it doesn’t matter that the arg is meaningless.)

Comments (2)

  1. Log in to comment