Microsoft KB Archive/172556: Difference between revisions

From BetaArchive Wiki
m (Text replacement - """ to """)
m (Text replacement - "&" to "&")
 
Line 57: Line 57:
<li>Start a MAPI Session by calling MAPILogonEx.</li>
<li>Start a MAPI Session by calling MAPILogonEx.</li>
<li><p>Call IMAPISession::AdminServices to get an IMsgServiceAdmin pointer for making changes to message services. The call should look something like the following:</p>
<li><p>Call IMAPISession::AdminServices to get an IMsgServiceAdmin pointer for making changes to message services. The call should look something like the following:</p>
<pre class="codesample">      hr = m_lpSession->AdminServices(0, &amp;m_lpServiceAdmin);
<pre class="codesample">      hr = m_lpSession->AdminServices(0, &m_lpServiceAdmin);
                         </pre></li>
                         </pre></li>
<li><p>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:</p>
<li><p>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:</p>
<pre class="codesample">      hr = m_lpServiceAdmin->GetMsgServiceTable(0, &amp;m_lpMsgSvcTable);</pre></li>
<pre class="codesample">      hr = m_lpServiceAdmin->GetMsgServiceTable(0, &m_lpMsgSvcTable);</pre></li>
<li><p>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.:</p>
<li><p>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.:</p>
<pre class="codesample">      PR_SERVICE_NAME = "MSEMS"
<pre class="codesample">      PR_SERVICE_NAME = "MSEMS"
Line 73: Line 73:
                                                     PR_SERVICE_UID}};
                                                     PR_SERVICE_UID}};


       // Restrict the columns to just PR_DISPLAY_NAME &amp; PR_ENTRYID
       // Restrict the columns to just PR_DISPLAY_NAME & PR_ENTRYID
       hr = m_lpMsgSvcTable->SetColumns((LPSPropTagArray)&amp;Columns, 0);
       hr = m_lpMsgSvcTable->SetColumns((LPSPropTagArray)&Columns, 0);


       if (FAILED(hr))
       if (FAILED(hr))
Line 85: Line 85:
       sres.res.resProperty.relop = RELOP_EQ;
       sres.res.resProperty.relop = RELOP_EQ;
       sres.res.resProperty.ulPropTag = PR_SERVICE_NAME;
       sres.res.resProperty.ulPropTag = PR_SERVICE_NAME;
       sres.res.resProperty.lpProp = &amp;spv;
       sres.res.resProperty.lpProp = &spv;


       spv.ulPropTag = PR_SERVICE_NAME;
       spv.ulPropTag = PR_SERVICE_NAME;
Line 91: Line 91:


       // Call FindRow with that restriction
       // Call FindRow with that restriction
       hr = m_lpMsgSvcTable->FindRow(&amp;sres, BOOKMARK_BEGINNING, 0);
       hr = m_lpMsgSvcTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);


       if (SUCCEEDED(hr))
       if (SUCCEEDED(hr))
Line 98: Line 98:
         LPSPropValue  lpProp  =  NULL;
         LPSPropValue  lpProp  =  NULL;


         hr = m_lpMsgSvcTable->QueryRows(1, 0, &amp;lpRows);
         hr = m_lpMsgSvcTable->QueryRows(1, 0, &lpRows);


         if (FAILED(hr))
         if (FAILED(hr))
Line 115: Line 115:
         // We know that the 2nd row has the Service UID.
         // We know that the 2nd row has the Service UID.
         // See SetColumns() (above).
         // See SetColumns() (above).
         lpProp = &amp;lpRows->aRow[0].lpProps[1];
         lpProp = &lpRows->aRow[0].lpProps[1];


         if (lpProp->ulPropTag != PR_SERVICE_UID)
         if (lpProp->ulPropTag != PR_SERVICE_UID)
Line 124: Line 124:


         // Copy the UID into our member.
         // Copy the UID into our member.
         memcpy(&amp;m_ServiceUID.ab, lpProp->Value.bin.lpb,
         memcpy(&m_ServiceUID.ab, lpProp->Value.bin.lpb,
                 lpProp->Value.bin.cb);
                 lpProp->Value.bin.cb);


Line 132: Line 132:
                         </pre></li>
                         </pre></li>
<li><p>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:</p>
<li><p>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:</p>
<pre class="codesample">      hr = m_lpServiceAdmin->AdminProviders(&amp;m_ServiceUID,0,                                            &amp;m_lpProviderAdmin);</pre></li>
<pre class="codesample">      hr = m_lpServiceAdmin->AdminProviders(&m_ServiceUID,0,                                            &m_lpProviderAdmin);</pre></li>
<li><p>Now you need to get a table of all of MSEMS's Providers. This looks like the following:</p>
<li><p>Now you need to get a table of all of MSEMS's Providers. This looks like the following:</p>
<pre class="codesample">      hr = m_lpServiceAdmin->AdminProviders(&amp;m_ServiceUID,0,                                          &amp;m_lpProviderAdmin);</pre></li>
<pre class="codesample">      hr = m_lpServiceAdmin->AdminProviders(&m_ServiceUID,0,                                          &m_lpProviderAdmin);</pre></li>
<li><p>Restrict the columns to just the Display name and Provider UID. This looks like the following:</p>
<li><p>Restrict the columns to just the Display name and Provider UID. This looks like the following:</p>
<pre class="codesample">      // Restrict the columns to just PR_DISPLAY_NAME &amp; PR_SERVICE_UID
<pre class="codesample">      // Restrict the columns to just PR_DISPLAY_NAME & PR_SERVICE_UID
       static SizedSPropTagArray(2, Columns) = {2, {PR_DISPLAY_NAME,
       static SizedSPropTagArray(2, Columns) = {2, {PR_DISPLAY_NAME,
                                                   PR_PROVIDER_UID}};
                                                   PR_PROVIDER_UID}};


       hr = lpMTProviders->SetColumns((LPSPropTagArray)&amp;Columns, 0);
       hr = lpMTProviders->SetColumns((LPSPropTagArray)&Columns, 0);
                         </pre></li>
                         </pre></li>
<li><p>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:</p>
<li><p>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:</p>
Line 146: Line 146:
       sres.res.resProperty.relop = RELOP_EQ;
       sres.res.resProperty.relop = RELOP_EQ;
       sres.res.resProperty.ulPropTag = PR_DISPLAY_NAME;
       sres.res.resProperty.ulPropTag = PR_DISPLAY_NAME;
       sres.res.resProperty.lpProp = &amp;spv;
       sres.res.resProperty.lpProp = &spv;


       spv.ulPropTag = PR_DISPLAY_NAME;
       spv.ulPropTag = PR_DISPLAY_NAME;
Line 153: Line 153:
       // Apply the above restriction to just Providers with our
       // Apply the above restriction to just Providers with our
       // display name.
       // display name.
       hr = lpMTProviders->Restrict(&amp;sres, TBL_ASYNC);</pre></li>
       hr = lpMTProviders->Restrict(&sres, TBL_ASYNC);</pre></li>
<li><p>Go get the matching rows. This looks like the following:</p>
<li><p>Go get the matching rows. This looks like the following:</p>
<pre class="codesample">      // Set to beginning of table
<pre class="codesample">      // Set to beginning of table
       hr = lpMTProviders->SeekRow(BOOKMARK_BEGINNING,0,NULL);
       hr = lpMTProviders->SeekRow(BOOKMARK_BEGINNING,0,NULL);


       hr = lpMTProviders->QueryRows(4000, 0, &amp;lpRows); // Max 4000 rows.
       hr = lpMTProviders->QueryRows(4000, 0, &lpRows); // Max 4000 rows.
       // There should be at least one row
       // There should be at least one row
       if(lpRows->cRows == 0)
       if(lpRows->cRows == 0)
Line 170: Line 170:


       // We know that the 2nd row has the Service UID. See SetColumns()
       // We know that the 2nd row has the Service UID. See SetColumns()
       lpProp = &amp;lpRows->aRow[0].lpProps[1];
       lpProp = &lpRows->aRow[0].lpProps[1];


       // Allocate space for Service UID and return it.
       // Allocate space for Service UID and return it.
       hr = MAPIAllocateBuffer(lpProp->Value.bin.cb,
       hr = MAPIAllocateBuffer(lpProp->Value.bin.cb,
                               (LPVOID*)&amp;lpServiceUID);
                               (LPVOID*)&lpServiceUID);


       // copy the UID into our local.
       // copy the UID into our local.

Latest revision as of 12:30, 21 July 2020

Knowledge Base


HOWTO: Removing a Delegate From an Exchange Server Service

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:

  1. Start a MAPI Session by calling MAPILogonEx.
  2. 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);
                            
  3. 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);
  4. 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;
                            
  5. 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);
  6. 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);
  7. 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);
                            
  8. 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);
  9. 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!");
          }
                            
  10. 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);
                            
  11. 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