ComObjGet

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

ComObj := ComObjGet(Name)

Parameters

Name

Type: String

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

Return Value

Type: ComObject

This function returns a new COM wrapper object with the variant type VT_DISPATCH (9).

Error Handling

An exception is thrown on failure.

ComObject, ComObjActive, ComObjConnect, ComObjQuery, CoGetObject (Microsoft Docs)

Examples

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

+Esc::
{
    pid := WinGetPID("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(proc.CommandLine, "Command line", 0)
    else
        MsgBox("Process not found!")
}