COM::getObject Method

Returns an instance of a COM object that is running.


client server public static COM getObject(str className)

Run On



  • className
    Type: str
    The ProgID value or class name of the COM object that is used to create the instance of the COM class.

Return Value

Type: COM Class
An instance of the COM class for the class that is specified by the className parameter; nullNothingnullptrunita null reference (Nothing in Visual Basic) if the instance could not be created.


If multiple instances of the specified COM object are running, we cannot guarantee which instance will be returned by the getObject method.

Some COM objects do not support the extended features that enable calls to this method.


The following example shows how to retrieve an instance of a running COM object.

COM objExcel, objWorkBook, objWorkBooks; 
InteropPermission perm; 
// Set code access permission to help protect the use of 
perm = new InteropPermission(InteropKind::ComInterop); 
objExcel = COM::getObject("Excel.Application"); 
if (!objExcel) 
    // Unable to connect to a running instance of Microsoft Excel. 
    // Try starting it. 
    objExcel = new COM("Excel.Application"); 
    if (!objExcel) 
        Info ("Unable to find or create an instance of Excel"); 
        return;  // Or other error action. 
// Close code access permission scope. 
objWorkBooks = objExcel.workbooks(); 
if (objWorkBooks) 
    objWorkBook ="d:\\mydata\\book1.xls"); 

See Also

COM Class Method

COM::getObjectEx Method