Article ID: 172556
Article Last Modified on 8/18/2005
APPLIES TO
- Microsoft Messaging Application Programming Interface
- Microsoft Exchange Server 4.0 Standard Edition
- Microsoft Exchange Server 5.0 Standard Edition
This article was previously published under Q172556
SUMMARY
The following details the process of removing a Delegate from the Exchange Messaging Service. Delegates are the users that are displayed in the "Additional Mailboxes" section on the "Advanced" tab of the Exchange Server Properties.
MORE INFORMATION
Use the following steps to remove a Delegate from the Exchange Server service:
- Start a MAPI Session by calling MAPILogonEx.
Call IMAPISession::AdminServices to get an IMsgServiceAdmin pointer for making changes to message services. The call should look something like the following:
hr = m_lpSession->AdminServices(0, &m_lpServiceAdmin);
Call IMsgServiceAdmin::GetMsgServiceTable to provide access to the message service table, a listing of the message services in the profile. This call should look something like the following:
hr = m_lpServiceAdmin->GetMsgServiceTable(0, &m_lpMsgSvcTable);
Now that you have a table of all of the Messaging Services, you need to find the Exchange Server Service. You do this by first calling SetColumns to specify that you want to see only PR_DISPLAY_NAME and PR_SERVICE_UID in the table. Next, you create a restriction that specifies the following and call FindRow with this restriction.:
PR_SERVICE_NAME = "MSEMS"
Then, you call QueryRows() to get a pointer to the returned SRowSet. At this point, you should have a single row that contains the Exchange Server PR_DISPLAY_NAME and PR_SERVICE_UID properties. Store the PR_SERVICE_UID because you will need it later. Here is a sample of what this process looks like:
HRESULT hr = NOERROR; static SRestriction sres; SPropValue spv; LPSRowSet lpRows = NULL; static SizedSPropTagArray(2, Columns) = {2, {PR_DISPLAY_NAME, PR_SERVICE_UID}}; // Restrict the columns to just PR_DISPLAY_NAME & PR_ENTRYID hr = m_lpMsgSvcTable->SetColumns((LPSPropTagArray)&Columns, 0); if (FAILED(hr)) { goto cleanup; } // Set up a restriction for the Exchange Server Service. sres.rt = RES_PROPERTY; sres.res.resProperty.relop = RELOP_EQ; sres.res.resProperty.ulPropTag = PR_SERVICE_NAME; sres.res.resProperty.lpProp = &spv; spv.ulPropTag = PR_SERVICE_NAME; spv.Value.lpszA = "MSEMS"; // Call FindRow with that restriction hr = m_lpMsgSvcTable->FindRow(&sres, BOOKMARK_BEGINNING, 0); if (SUCCEEDED(hr)) { // We have found the Service. Go get it. LPSPropValue lpProp = NULL; hr = m_lpMsgSvcTable->QueryRows(1, 0, &lpRows); if (FAILED(hr)) { goto cleanup; } // It would not make sense to have more than one row returned in // this case. if (lpRows->cRows != 1) { hr = (E_FAIL); goto cleanup; } // We know that the 2nd row has the Service UID. // See SetColumns() (above). lpProp = &lpRows->aRow[0].lpProps[1]; if (lpProp->ulPropTag != PR_SERVICE_UID) { hr = (E_FAIL); goto cleanup; } // Copy the UID into our member. memcpy(&m_ServiceUID.ab, lpProp->Value.bin.lpb, lpProp->Value.bin.cb); } cleanup: return hr;
Using the Service UID obtained from step 4, call IMsgServiceAdmin::AdminProviders to obtain a pointer that will provide access to the Exchange Server Service administration object. This looks like the following:
hr = m_lpServiceAdmin->AdminProviders(&m_ServiceUID,0, &m_lpProviderAdmin);
Now you need to get a table of all of MSEMS's Providers. This looks like the following:
hr = m_lpServiceAdmin->AdminProviders(&m_ServiceUID,0, &m_lpProviderAdmin);
Restrict the columns to just the Display name and Provider UID. This looks like the following:
// Restrict the columns to just PR_DISPLAY_NAME & PR_SERVICE_UID static SizedSPropTagArray(2, Columns) = {2, {PR_DISPLAY_NAME, PR_PROVIDER_UID}}; hr = lpMTProviders->SetColumns((LPSPropTagArray)&Columns, 0);
Set up a restriction on the name we are looking for. Make sure the name is in the same format as it appears in your mail client. For example, it frequently looks like "Mailbox - Jonathan Larson." This looks like the following:
sres.rt = RES_PROPERTY; sres.res.resProperty.relop = RELOP_EQ; sres.res.resProperty.ulPropTag = PR_DISPLAY_NAME; sres.res.resProperty.lpProp = &spv; spv.ulPropTag = PR_DISPLAY_NAME; spv.Value.lpszA = "Mailbox - Jonathan Larson"; //Name to find. // Apply the above restriction to just Providers with our // display name. hr = lpMTProviders->Restrict(&sres, TBL_ASYNC);
Go get the matching rows. This looks like the following:
// Set to beginning of table hr = lpMTProviders->SeekRow(BOOKMARK_BEGINNING,0,NULL); hr = lpMTProviders->QueryRows(4000, 0, &lpRows); // Max 4000 rows. // There should be at least one row if(lpRows->cRows == 0) { AfxMessageBox("Name not found!"); }
Now that we have the rows, get the Provider UID of the one to be deleted. This looks like the following:
// We've found the Service. Go get it. LPSPropValue lpProp = NULL; // We know that the 2nd row has the Service UID. See SetColumns() lpProp = &lpRows->aRow[0].lpProps[1]; // Allocate space for Service UID and return it. hr = MAPIAllocateBuffer(lpProp->Value.bin.cb, (LPVOID*)&lpServiceUID); // copy the UID into our local. memcpy(lpServiceUID->ab, lpProp->Value.bin.lpb, lpProp->Value.bin.cb);
Now that we have the Provider UID, we can call DeleteProvider with it.
hr = m_lpProviderAdmin->DeleteProvider(lpServiceUID);
REFERENCES
For additional information, please see the following article in the Microsoft Knowledge Base:
171636 HOWTO: Adding a Delegate to Exchange Server Messaging Service
Additional query words: Delegate EMSDelegate
Keywords: kbhowto kbapi kbmsg kbcode KB172556