Article ID: 172556
Article Last Modified on 8/18/2005
hr = m_lpSession->AdminServices(0, &m_lpServiceAdmin);
hr = m_lpServiceAdmin->GetMsgServiceTable(0, &m_lpMsgSvcTable);
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;
hr = m_lpServiceAdmin->AdminProviders(&m_ServiceUID,0, &m_lpProviderAdmin);
hr = m_lpServiceAdmin->AdminProviders(&m_ServiceUID,0, &m_lpProviderAdmin);
// 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);
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);
// 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!");
}
// 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);
hr = m_lpProviderAdmin->DeleteProvider(lpServiceUID);171636 HOWTO: Adding a Delegate to Exchange Server Messaging Service
Additional query words: Delegate EMSDelegate
Keywords: kbhowto kbapi kbmsg kbcode KB172556