Registering the Context Menu COM Object in a Display Specifier

When you use COM to create a context menu extension DLL for an Active Directory directory service, the extension must be registered with the Windows registry and Active Directory Domain Services to notify the Active Directory administrative MMC snap-ins and the Windows shell of the extension.

Registering in the Windows Registry

Like all COM servers, a context menu extension must be registered in the 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 Domain Services

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 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 objects of Active Directory Domain Services.

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 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 the Active Directory server. 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 a code example of how to implement a context menu extension, see Example Code for Implementation of the Context Menu COM Object.