ComObject

Linux port: COM is implemented over the D-Bus desktop bus: ComObject("org.freedesktop.DBus") creates a proxy for a bus service, method calls and property access map to D-Bus calls, and ComValue wraps typed values. Windows COM interfaces (IUnknown/IDispatch pointers, SafeArrays) do not exist on Linux.

Creates a COM object.

ComObj := ComObject(CLSID , IID)

ComObject itself is a class derived from ComValue, but is used only to create or identify COM objects.

Parameters

CLSID

Type: String

CLSID or human-readable Prog ID of the COM object to create.

IID

Type: String

If omitted, it defaults to "{00020400-0000-0000-C000-000000000046}" (IID_IDispatch). Otherwise, specify the identifier of the interface to return. In most cases this is omitted.

Return Value

Type: Object

This function returns a COM wrapper object of type dependent on the IID parameter.

IIDClassVariant TypeDescription
IID_IDispatch ComObject VT_DISPATCH (9) Allows the script to call properties and methods of the object using normal object syntax.
Any other IID ComValue VT_UNKNOWN (13) Provides only a Ptr property, which allows the object to be passed to DllCall or ComCall.

Error Handling

An exception is thrown on failure, such as if a parameter is invalid or the object does not support the interface specified by IID.

ComValue, ComObjGet, ComObjActive, ComObjConnect, ComObjArray, ComObjQuery, ComCall, CreateObject (Microsoft Docs)

Examples

For a long list of v1.1 examples, see this archived forum thread.

Linux: COM is implemented over the D-Bus desktop bus on this port. ComObject("service") creates a proxy for a bus service; method calls and property access map to D-Bus. The Windows examples below (Internet Explorer, Active Desktop) cannot run on Linux.

; Create a proxy for the D-Bus daemon itself.
bus := ComObject("org.freedesktop.DBus")

; Call a method: GetId() returns the bus id.
id := bus.GetId()
MsgBox "bus id: " id  ; e.g. 07ab...  (non-empty)

; ListNames() returns an Array of service names (string array).
names := bus.ListNames()
MsgBox "services: " names.Length
for name in names
    OutputDebug name

; Property access is supported via org.freedesktop.DBus.Properties;
; calling an unknown member raises an OSError rather than crashing.
try
    bus.NoSuchMethod()
catch
    MsgBox "unknown member raised an error"

Launches an instance of Internet Explorer, makes it visible and navigates to a website.

ie := ComObject("InternetExplorer.Application")
ie.Visible := true  ; This is known to work incorrectly on IE7.
ie.Navigate("https://www.autohotkey.com/")

Retrieves the path of the desktop's current wallpaper.

AD_GETWP_BMP := 0
AD_GETWP_LAST_APPLIED := 0x00000002
CLSID_ActiveDesktop := "{75048700-EF1F-11D0-9888-006097DEACF9}"
IID_IActiveDesktop := "{F490EB00-1240-11D1-9888-006097DEACF9}"
cchWallpaper := 260
GetWallpaper := 4

AD := ComObject(CLSID_ActiveDesktop, IID_IActiveDesktop)
wszWallpaper := Buffer(cchWallpaper * 2)
ComCall(GetWallpaper, AD, "ptr", wszWallpaper, "uint", cchWallpaper, "uint", AD_GETWP_LAST_APPLIED)
Wallpaper := StrGet(wszWallpaper, "UTF-16")
MsgBox "Wallpaper: " Wallpaper