ComObjGet() [AHK_L 53+]

Returns a reference to an object provided by a COM component.

ComObject := ComObjGet(Name)

Parameters

Name

The display name of the object to be retrieved. See MkParseDisplayName (Microsoft Docs) for more information.

Remarks

On failure, the function may throw an exception, exit the script or return an empty string, depending on the current ComObjError() setting and other factors.

ComObjCreate(), ComObjActive(), ComObjConnect(), ComObjError(), ComObjQuery(), CoGetObject (Microsoft Docs)

Examples

Press Shift+Esc to show the command line which was used to launch the active window's process. Requires XP or later. For Win32_Process, see Microsoft Docs.

+Esc::
    WinGet pid, PID, A
    ; Get WMI service object.
    wmi := ComObjGet("winmgmts:")
    ; Run query to retrieve matching process(es).
    queryEnum := wmi.ExecQuery(""
        . "Select * from Win32_Process where ProcessId=" . pid)
        ._NewEnum()
    ; Get first matching process.
    if queryEnum[proc]
        MsgBox 0, Command line, % proc.CommandLine
    else
        MsgBox Process not found!
    ; Free all global objects (not necessary when using local vars).
    wmi := queryEnum := proc := ""
return