Export (0) Print
Expand All

Marshal.GetActiveObject Method

Obtains a running instance of the specified object from the running object table (ROT).

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

static member GetActiveObject : 
        progID:string -> Object

Parameters

progID
Type: System.String

The programmatic identifier (ProgID) of the object that was requested.

Return Value

Type: System.Object
The object that was requested; otherwise a null reference (Nothing in Visual Basic). You can cast this object to any COM interface that it supports.

ExceptionCondition
COMException

The object was not found.

GetActiveObject exposes the COM GetActiveObject Function function from OLEAUT32.DLL; however, the latter expects a class identifier (CLSID) instead of the programmatic identifier (ProgID) expected by this method. To obtain a running instance of a COM object without a registered ProgID, use platform invoke to define the COM GetActiveObject Function function. For a description of platform invoke, see Consuming Unmanaged DLL Functions.

ProgID and CLSID

Keys in the HKEY_CLASSES_ROOT subtree of the registry contain a variety of subkey types. Most of the subkeys are ProgIDs, which map a user-friendly string to a CLSID. Applications often use these human-readable strings instead of the numeric CLSIDs. Often, a component has a version-independent ProgID that is mapped to the latest version of the component that is installed on the system.

Applications and components primarily use ProgIDs to retrieve their corresponding CLSIDs.

The following example was run on a computer that was configured with a running instance of Microsoft Word. There were no instances of Microsoft Excel running.

The example calls GetActiveObject twice. The first call tries to retrieve a reference to an instance of Microsoft Word (an instance of the Word.Application object). The second call tries to retrieve a reference to an instance of Microsoft Excel (an instance of an Excel.Application object).

The code retrieves a reference to an instance of Microsoft Word successfully. However, because Microsoft Excel is not running, the attempt to retrieve the second object raises a COMException.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft