Using the IRSOPInformation Interface

The main RSoP snap-in has the same architecture as the Group Policy Object Editor. When you write an RSoP extension snap-in, you must query the IRSOPInformation interface using the CComponentData::Notify method. This technique is similar to using the IGPEInformation interface to communicate with the Group Policy Object Editor using an extension snap-in.

The following code example shows how to use the IRSOPInformation interface to connect to the WMI namespace that contains the RSoP data. Your snap-in must first query for the namespace and then connect to the namespace using the IWbemLocator::ConnectServer method. ConnectServer returns a IWbemServices interface pointer that is required for the lifetime of your RSoP snap-in. You can use this interface pointer to search for objects of a particular class. For more information, see Querying for Group Policy WMI Objects.

//
// This is how the Administrative Templates extension 
//    queries for the IRSOPInformation interface and 
//    connects to the namespace.
//
STDMETHODIMP CPolicyComponentData::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
{
    HRESULT hr = S_OK;

    switch(event)
    {
        case MMCN_EXPAND:
            if (arg == TRUE)

                if (m_bRSOP)
                {
                    if (!m_pRSOPInformation)
                    {
                         //
                         // Query for the IRSOPInformation interface.
                         //
                        lpDataObject->QueryInterface(IID_IRSOPInformation, (LPVOID *)&m_pRSOPInformation);

                        if (m_pRSOPInformation)
                        {
                            m_pszNamespace = (LPOLESTR) LocalAlloc (LPTR, 350 * sizeof(TCHAR));

                            if (m_pszNamespace)
                            {
                                //
                                // Retrieve the namespace from the main RSoP snap-in.
                                //
                                if (m_pRSOPInformation->GetNamespace((m_bUserScope ? GPO_SECTION_USER : GPO_SECTION_MACHINE),
                                                                      m_pszNamespace, 350) == S_OK)
                                {
                                    IWbemLocator *pIWbemLocator;

                                     //
                                     // Connect to the namespace using the WbemLocator::ConnectServer method.
                                     //
                                    if (CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER,
                                                         IID_IWbemLocator, (LPVOID *) &pIWbemLocator) == S_OK)
                                    {
                                        BSTR pNamespace = SysAllocString (m_pszNamespace);

                                        if (pNamespace)
                                        {
                                            pIWbemLocator->ConnectServer(pNamespace,
                                                                         NULL, NULL,
                                                                         0L, 0L,
                                                                         NULL, NULL,
                                                                         &m_pIWbemServices);
                                            SysFreeString (pNamespace);
                                        }

                                        pIWbemLocator->Release();
                                    }
                                }
                            }
                        }
                    }

                    if (m_pIWbemServices)
                    {
                        hr = EnumerateScopePane(lpDataObject, (HSCOPEITEM)param);
                    }
                }
                else
                {
                    if (!m_pGPTInformation)
                    {
                        lpDataObject->QueryInterface(IID_IGPEInformation, (LPVOID *)&m_pGPTInformation);
                    }

                    if (m_pGPTInformation)
                    {
                        hr = EnumerateScopePane(lpDataObject, (HSCOPEITEM)param);
                    }
                }
            break;

        default:
            break;
    }

    return hr;
}

For more information about MMC, see the Microsoft Management Console.