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.



Type: String

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


Type: String

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

Return Value

Type: ComValue or ComObject

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 (MSDN)


For a long list of examples, see the following forum topic:

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.

Retrieve the path of the desktop's current wallpaper.

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