Platform SDK: Active Directory, ADSI, and Directory Services

Registering the Context Menu COM Object in a Display Specifier

Even after you've written and installed your context menu COM object, the Windows shell and Active Directory administrative snap-ins cannot recognize it yet. For the Windows shell or Active Directory administrative snap-ins to recognize your context menu, you must add a value for your context menu COM object in the adminContextMenu and/or shellContextMenu property of the display specifier for the class whose context menu you want to extend. Note that you can register the same context menu COM object for more than one class.

If the COM object was registered in the adminContextMenu property of the class's display specifier, the context menu appears when the user opens the context menu for objects of that class in Active Directory administrative snap-ins. If it was registered in shellContextMenu, the context menu appears in the Windows shell. If you want it to appear in both the shell and administrative snap-ins, you need to register the COM object in both properties.

The adminContextMenu and shellContextMenu properties are multi-valued. The adminContextMenu contains the list of context menus for Active Directory administrative snap-ins to add to the context menu for the object class. The shellContextMenu contains the list for the Windows shell.

For a context menu COM object, the value is a string with the following format:

ordernumber,CLSID

In this example, the ordernumber is a signed number that represents the menu item's position on the context menu. When a context menu is first displayed, the values are sorted using a signed comparison of each value's ordernumber. If more than one value has the same ordernumber, those context menu COM objects are loaded in the order they are read from the directory; however, you should use a non-existing ordernumber (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 ordernumber sequence.

The CLSID is the CLSID of the context menu's COM object in the string format produced by the StringFromGUID2 function in the COM library. Note that the COM object must implement the IContextMenu and IShellExtInit interfaces.

Example:

1,{08eb4fa6-6ffd-11d1-b0e0-00c04fd8dca6} 

Adding a Value to the adminContextMenu or shellContextMenu properties

When you add a value for your context menu COM object to adminContextMenu or shellContextMenu, follow these rules:

  1. Make sure it hasn't already been added.
  2. Add a new value at the end of the context menu ordering list. This means setting the ordernumber portion of the value to the next value after the highest existing ordernumber.
  3. To add the value, use the IADs::PutEx method with the lnControlCode parameter set to ADS_PROPERTY_APPEND so that the value will be added to the existing values (and, therefore, not overwrite the existing values). Make sure you call IADs::SetInfo to commit the change to the directory.

For sample code that adds a value to a displaySpecifier object, see Registering the Property Page COM Object in a Display Specifier.