Directory Services

Registering the Context Menu COM Object in a Display Specifier

When a Microsoft® Active Directory® directory service context menu extension DLL is created, it must be registered with the Windows registry and Active Directory to make COM, the Active Directory administrative MMC snap-ins and the Windows® shell aware of the extension.

Registering in the Windows Registry

Like all COM servers, a context menu extension must be registered in the Windows registry. The extension is registered under the following key.

HKEY_CLASSES_ROOT
     CLSID
          <clsid>

<clsid> is the string representation of the CLSID as produced by the StringFromCLSID function. Under the <clsid> key, there is an InProcServer32 key that identifies the object as a 32-bit in-proc server. Under the InProcServer32 key, the location of the DLL is specified in the default value and the threading model is specified in the ThreadingModel value. All context menu extension must use the Apartment threading model.

Registering with Active Directory

Context menu extension registration is specific to one locale. If the context menu extension applies to all locales, it must be registered in the object class displaySpecifier object in all of the locale subcontainers in the Display Specifiers container. If the context menu extension is localized for a certain locale, it must be registered in the displaySpecifier object in that locale's subcontainer. For more information about the Display Specifiers container and locales, see Display Specifiers and DisplaySpecifiers Container.

There are two display specifier attributes that a context menu extension item can be registered under. These are adminContextMenu and shellContextMenu.

The adminContextMenu attribute identifies administrative context menus to display in Active Directory administrative snap-ins. The context menu appears when the user displays the context menu for objects of the appropriate class in one of the Active Directory administrative MMC snap-ins.

The shellContextMenu attribute identifies end-user context menus to display in the Microsoft Windows® shell. The context menu appears when the user views the context menu for objects of the appropriate class in the Windows Explorer. Beginning with Windows Server 2003, the Windows shell no longer displays Active Directory objects.

All of these attributes are multi-valued.

When registering a context menu extension, the values for the adminContextMenu and shellContextMenu attributes require the following format.

<order number>,<clsid>

The <order number> is an unsigned number that represents the item's position in the context menu. When a context menu is displayed, the values are sorted using a comparison of each value's <order number>. If more than one value has the same <order number>, those context menu extensions are loaded in the order they are read from Active Directory. If possible, use a non-existing <order number>, that is, one that has not been used by other values in the property. There is no prescribed starting position and gaps are allowed in the <order number> sequence.

The <clsid> is the string representation of the CLSID as produced by the StringFromCLSID function.

In the Windows shell, multiple-selection context menu items are supported. In this case, the context menu extension is invoked for each selected object. In Active Directory administrative snap-ins, multiple-selection context menu extension items are also supported. In this case, the DSOBJECTNAMES structure will contain a DSOBJECT structure for each directory object selected.

Important  For the Windows shell, display specifier information is retrieved at user logon and cached for the user's session. For the administrative snap-ins, the display specifier data is retrieved when the snap-in is loaded and is cached for the duration of the process. For the Windows shell, this means changes to display specifiers take effect after a user logs off and back on again. For the administrative snap-ins, changes take effect when the snap-in or console file is reloaded, that is, if you start a new instance of the console file or new Mmc.exe instance and add the snap-in, the latest display specifier data is retrieved.

For more information, and an example of how to implement a context menu extension, see Example Code for Implementation of the Context Menu COM Object.