Microsoft KB Archive/306962: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(2 intermediate revisions by the same user not shown)
Line 112: Line 112:
     if (FAILED(hRes = MAPIInitialize(NULL)))
     if (FAILED(hRes = MAPIInitialize(NULL)))
     {
     {
         cout<<"Error initializing MAPI. hRes = 0x"<<hex<<hRes<<dec<<endl;
         cout<<&quot;Error initializing MAPI. hRes = 0x&quot;<<hex<<hRes<<dec<<endl;
         return FALSE;
         return FALSE;
     }
     }


     // Instruct user to click the &quot;New&quot; button.
     // Instruct user to click the &quot;New&quot; button.
     cout&lt;&lt;&quot;When the \&quot;Choose Profile\&quot; dialog appears, click the \&quot;New\&quot; button&quot;
     cout<<&quot;When the \&quot;Choose Profile\&quot; dialog appears, click the \&quot;New\&quot; button&quot;
         &lt;&lt;&quot;to configure a new profile.&quot;&lt;&lt;endl;
         <<&quot;to configure a new profile.&quot;<<endl;


     // Call MAPILogonEx to display the profile chooser dialog box.
     // Call MAPILogonEx to display the profile chooser dialog box.
Line 125: Line 125:
                                   NULL,
                                   NULL,
                                   MAPI_LOGON_UI,
                                   MAPI_LOGON_UI,
                                   &amp;lpSession)))
                                   &lpSession)))
     {
     {
         cout&lt;&lt;&quot;Error logging on. hRes = 0x&quot;&lt;&lt;hex&lt;&lt;hRes&lt;&lt;dec&lt;&lt;endl;
         cout<<&quot;Error logging on. hRes = 0x&quot;<<hex<<hRes<<dec<<endl;
         return FALSE;
         return FALSE;
     }
     }


     // Log off the session.
     // Log off the session.
     if (FAILED(hRes = lpSession-&gt;Logoff(0,0,0)))
     if (FAILED(hRes = lpSession->Logoff(0,0,0)))
     {
     {
         cout&lt;&lt;&quot;Error logging off. hRes = 0x&quot;&lt;&lt;hex&lt;&lt;hRes&lt;&lt;dec&lt;&lt;endl;
         cout<<&quot;Error logging off. hRes = 0x&quot;<<hex<<hRes<<dec<<endl;
     }
     }


     // Release the session.
     // Release the session.
     lpSession-&gt;Release();
     lpSession->Release();


     // Uninitialize MAPI.
     // Uninitialize MAPI.
Line 167: Line 167:
                                   szProfName)))
                                   szProfName)))
     {
     {
         cout&lt;&lt;&quot;Error launching wizard. hRes = 0x&quot;&lt;&lt;hex&lt;&lt;hRes&lt;&lt;dec&lt;&lt;endl;
         cout<<&quot;Error launching wizard. hRes = 0x&quot;<<hex<<hRes<<dec<<endl;
         return FALSE;
         return FALSE;
     }
     }
Line 201: Line 201:


     // Get configuration info from user.
     // Get configuration info from user.
     cout&lt;&lt;&quot;Enter name for profile: &quot;;
     cout<<&quot;Enter name for profile: &quot;;
     cin&gt;&gt;szProfile;
     cin>>szProfile;
     cout&lt;&lt;&quot;Enter Exchange mailbox name: &quot;;
     cout<<&quot;Enter Exchange mailbox name: &quot;;
     cin&gt;&gt;szMailbox;
     cin>>szMailbox;
     cout&lt;&lt;&quot;Enter Exchange server name: &quot;;
     cout<<&quot;Enter Exchange server name: &quot;;
     cin&gt;&gt;szServer;
     cin>>szServer;


     // Initialize MAPI.
     // Initialize MAPI.
Line 212: Line 212:
     if (FAILED(hRes = MAPIInitialize(NULL)))
     if (FAILED(hRes = MAPIInitialize(NULL)))
     {
     {
         cout&lt;&lt;&quot;Error initializing MAPI.&quot;;
         cout<<&quot;Error initializing MAPI.&quot;;
         goto error;
         goto error;
     }
     }
Line 219: Line 219:


     if (FAILED(hRes = MAPIAdminProfiles(0,              // Flags.
     if (FAILED(hRes = MAPIAdminProfiles(0,              // Flags.
                                         &amp;lpProfAdmin))) // Pointer to new IProfAdmin.
                                         &lpProfAdmin))) // Pointer to new IProfAdmin.
     {
     {
         cout&lt;&lt;&quot;Error getting IProfAdmin interface.&quot;;
         cout<<&quot;Error getting IProfAdmin interface.&quot;;
         goto error;
         goto error;
     }
     }
Line 227: Line 227:
     // Create a new profile.
     // Create a new profile.


     if (FAILED(hRes = lpProfAdmin-&gt;CreateProfile(szProfile,    // Name of new profile.
     if (FAILED(hRes = lpProfAdmin->CreateProfile(szProfile,    // Name of new profile.
                                                 NULL,          // Password for profile.
                                                 NULL,          // Password for profile.
                                                 NULL,          // Handle to parent window.
                                                 NULL,          // Handle to parent window.
                                                 NULL)))        // Flags.
                                                 NULL)))        // Flags.
     {
     {
         cout&lt;&lt;&quot;Error creating profile.&quot;;
         cout<<&quot;Error creating profile.&quot;;
         goto error;
         goto error;
     }
     }
Line 238: Line 238:
     // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
     // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.


     if (FAILED(hRes = lpProfAdmin-&gt;AdminServices(szProfile,    // Profile that we want to modify.
     if (FAILED(hRes = lpProfAdmin->AdminServices(szProfile,    // Profile that we want to modify.
                                                 NULL,          // Password for that profile.
                                                 NULL,          // Password for that profile.
                                                 NULL,          // Handle to parent window.
                                                 NULL,          // Handle to parent window.
                                                 0,            // Flags.
                                                 0,            // Flags.
                                                 &amp;lpSvcAdmin))) // Pointer to new IMsgServiceAdmin.
                                                 &lpSvcAdmin))) // Pointer to new IMsgServiceAdmin.
     {
     {
         cout&lt;&lt;&quot;Error getting IMsgServiceAdmin interface.&quot;;
         cout<<&quot;Error getting IMsgServiceAdmin interface.&quot;;
         goto error;
         goto error;
     }
     }
Line 250: Line 250:
     // Create the new message service for Exchange.
     // Create the new message service for Exchange.


     if (FAILED(hRes = lpSvcAdmin-&gt;CreateMsgService(&quot;MSEMS&quot;,    // Name of service from MAPISVC.INF.
     if (FAILED(hRes = lpSvcAdmin->CreateMsgService(&quot;MSEMS&quot;,    // Name of service from MAPISVC.INF.
                                                   NULL,        // Display name of service.
                                                   NULL,        // Display name of service.
                                                   NULL,        // Handle to parent window.
                                                   NULL,        // Handle to parent window.
                                                   NULL)))      // Flags.
                                                   NULL)))      // Flags.
     {
     {
         cout&lt;&lt;&quot;Error creating Exchange message service.&quot;;
         cout<<&quot;Error creating Exchange message service.&quot;;
         goto error;
         goto error;
     }
     }
Line 263: Line 263:
     // and getting the entry that corresponds to the new service.
     // and getting the entry that corresponds to the new service.


     if (FAILED(hRes = lpSvcAdmin-&gt;GetMsgServiceTable(0,                // Flags.
     if (FAILED(hRes = lpSvcAdmin->GetMsgServiceTable(0,                // Flags.
                                                     &amp;lpMsgSvcTable)))  // Pointer to table.
                                                     &lpMsgSvcTable)))  // Pointer to table.
     {
     {
         cout&lt;&lt;&quot;Error getting Message Service Table.&quot;;
         cout<<&quot;Error getting Message Service Table.&quot;;
         goto error;
         goto error;
     }
     }
Line 275: Line 275:
     sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
     sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
     sres.res.resContent.ulPropTag = PR_SERVICE_NAME;
     sres.res.resContent.ulPropTag = PR_SERVICE_NAME;
     sres.res.resContent.lpProp = &amp;SvcProps;
     sres.res.resContent.lpProp = &SvcProps;


     SvcProps.ulPropTag = PR_SERVICE_NAME;
     SvcProps.ulPropTag = PR_SERVICE_NAME;
Line 283: Line 283:


     if (FAILED(hRes = HrQueryAllRows(lpMsgSvcTable,
     if (FAILED(hRes = HrQueryAllRows(lpMsgSvcTable,
                                     (LPSPropTagArray)&amp;sptCols,
                                     (LPSPropTagArray)&sptCols,
                                     &amp;sres,
                                     &sres,
                                     NULL,
                                     NULL,
                                     0,
                                     0,
                                     &amp;lpSvcRows)))
                                     &lpSvcRows)))
     {
     {
         cout&lt;&lt;&quot;Error querying table for new message service.&quot;;
         cout<<&quot;Error querying table for new message service.&quot;;
         goto error;
         goto error;
     }
     }
Line 296: Line 296:


     // First, the server name.
     // First, the server name.
     ZeroMemory(&amp;rgval[1], sizeof(SPropValue) );
     ZeroMemory(&rgval[1], sizeof(SPropValue) );
     rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
     rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
     rgval[1].Value.lpszA = szServer;
     rgval[1].Value.lpszA = szServer;


     // Next, the mailbox name.
     // Next, the mailbox name.
     ZeroMemory(&amp;rgval[0], sizeof(SPropValue) );
     ZeroMemory(&rgval[0], sizeof(SPropValue) );
     rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_NAME;  
     rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_NAME;  
     rgval[0].Value.lpszA = szMailbox;
     rgval[0].Value.lpszA = szMailbox;
Line 307: Line 307:
     // Configure the message service by using the previous properties.
     // Configure the message service by using the previous properties.


         if (FAILED(hRes = lpSvcAdmin-&gt;ConfigureMsgService(
         if (FAILED(hRes = lpSvcAdmin->ConfigureMsgService(
         (LPMAPIUID)lpSvcRows-&gt;aRow-&gt;lpProps[iSvcUID].Value.bin.lpb, // Entry ID of service to configure.
         (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb, // Entry ID of service to configure.
         NULL,                                                      // Handle to parent window.
         NULL,                                                      // Handle to parent window.
         0,                                                          // Flags.
         0,                                                          // Flags.
Line 314: Line 314:
         rgval)))                                                    // Pointer to SPropValue array.
         rgval)))                                                    // Pointer to SPropValue array.
     {
     {
         cout&lt;&lt;&quot;Error configuring message service.&quot;;
         cout<<&quot;Error configuring message service.&quot;;
         goto error;
         goto error;
     }
     }
Line 321: Line 321:


error:
error:
     cout&lt;&lt;&quot; hRes = 0x&quot;&lt;&lt;hex&lt;&lt;hRes&lt;&lt;dec&lt;&lt;endl;
     cout<<&quot; hRes = 0x&quot;<<hex<<hRes<<dec<<endl;
     return FALSE;
     return FALSE;


Line 327: Line 327:
     // Clean up.
     // Clean up.
     if (lpSvcRows) FreeProws(lpSvcRows);
     if (lpSvcRows) FreeProws(lpSvcRows);
     if (lpMsgSvcTable) lpMsgSvcTable-&gt;Release();
     if (lpMsgSvcTable) lpMsgSvcTable->Release();
     if (lpSvcAdmin) lpSvcAdmin-&gt;Release();
     if (lpSvcAdmin) lpSvcAdmin->Release();
     if (lpProfAdmin) lpProfAdmin-&gt;Release();
     if (lpProfAdmin) lpProfAdmin->Release();


     MAPIUninitialize();
     MAPIUninitialize();

Latest revision as of 14:13, 21 July 2020

Article ID: 306962

Article Last Modified on 10/25/2007



APPLIES TO

  • Microsoft Exchange Server 2003 Enterprise Edition
  • Microsoft Exchange Server 2003 Standard Edition
  • Microsoft Exchange 2000 Server Standard Edition
  • Microsoft Exchange Server 5.5 Standard Edition
  • Microsoft Messaging Application Programming Interface



This article was previously published under Q306962

SUMMARY

A common misconception is that a MAPI client, such as Microsoft Outlook or the Exchange Client, must be installed on a Microsoft Exchange Server to create MAPI profiles. Installing a MAPI client for this reason is unnecessary. For Outlook, we do not recommend that you install a MAPI client for production servers. As long as a MAPI subsystem is installed, a variety of other ways exist to create MAPI profiles. In Exchange, a MAPI subsystem is installed.

MORE INFORMATION

Methods of creating MAPI profiles

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Before you try any one of these methods, you will have to make sure that the correct entries are made in the Mapisvc.inf file on the server. For more information about how to modify this file, click the following article number to view the article in the Microsoft Knowledge Base:

294470 How to add entries for Exchange services to Mapisvc.inf


Use NewProf.exe

The NewProf.exe utility is included with Outlook. For more information about how to use this utility, visit the following Microsoft Developer Network (MSDN) Web site:

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

145905 Newprof.exe command-line options


148664 Description of the Profile Descriptor File


Use the ProfMan2 sample

This sample uses the MAPI IProfAdmin interface that is mentioned in the "Use the MAPI IProfAdmin interface" section. To obtain this sample, click the following article number to view the article in the Microsoft Knowledge Base:

228736 Profman2.exe - MAPI Profile Manager v2.0


Use the MAPILogonEx function

When you call the MAPILogonEx function without specifying a profile and by setting the MAPI_LOGON_UI flag, MAPI displays the profile creation wizard if no profiles are on the computer. If profiles exist, MAPI displays the Choose Profile dialog box. Click New to start the profile creation wizard.

Sample code
// CreateProfileWithMAPILogonEx function: This takes advantage of the 
// profile prompt dialog's "New" button.
bool CreateProfileWithMAPILogonEx()
{
    HRESULT         hRes = S_OK;        // Return code from MAPI calls.
    LPMAPISESSION   lpSession = NULL;   // MAPI Session pointer.

    // Initialize MAPI.
    if (FAILED(hRes = MAPIInitialize(NULL)))
    {
        cout<<"Error initializing MAPI. hRes = 0x"<<hex<<hRes<<dec<<endl;
        return FALSE;
    }

    // Instruct user to click the "New" button.
    cout<<"When the \"Choose Profile\" dialog appears, click the \"New\" button"
        <<"to configure a new profile."<<endl;

    // Call MAPILogonEx to display the profile chooser dialog box.
    if (FAILED(hRes = MAPILogonEx(NULL,
                                  NULL,
                                  NULL,
                                  MAPI_LOGON_UI,
                                  &lpSession)))
    {
        cout<<"Error logging on. hRes = 0x"<<hex<<hRes<<dec<<endl;
        return FALSE;
    }

    // Log off the session.
    if (FAILED(hRes = lpSession->Logoff(0,0,0)))
    {
        cout<<"Error logging off. hRes = 0x"<<hex<<hRes<<dec<<endl;
    }

    // Release the session.
    lpSession->Release();

    // Uninitialize MAPI.
    MAPIUninitialize();

    // true, which indicates success.
    return TRUE;
}
                

Use the LAUNCHWIZARDENTRY function

This function directly calls the profile creation wizard.

Sample code
// CreateProfileWithLAUNCHWIZARD function: This uses the LAUNCHWIZARDENTRY API
// to display the profile configuration UI.
bool CreateProfileWithLAUNCHWIZARD()
{
    HRESULT     hRes = S_OK;                    // Return code from MAPI calls.
    TCHAR       szProfName[80] = {0};           // String to hold profile name.
    LPTSTR      szServices[] = {"MSEMS", NULL}; // String to hold message service names.

    // Call LaunchWizard to add the MSEMS service.
    if (FAILED(hRes = LaunchWizard(NULL,
                                   NULL,
                                   (LPCTSTR *)szServices,
                                   80,
                                   szProfName)))
    {
        cout<<"Error launching wizard. hRes = 0x"<<hex<<hRes<<dec<<endl;
        return FALSE;
    }

    // Return true indicating success.
    return TRUE;
}
                

Use the MAPI IProfAdmin interface

This MAPI interface lets you programmatically create a profile without user interaction.

Sample code
// CreateProfileWithIProfAdmin function: This uses the MAPI IProfAdmin to 
// programmatically create a profile. No UI is displayed.
bool CreateProfileWithIProfAdmin()
{
    HRESULT         hRes = S_OK;            // Result from MAPI calls.
    LPPROFADMIN     lpProfAdmin = NULL;     // Profile Admin object.
    LPSERVICEADMIN  lpSvcAdmin = NULL;      // Service Admin object.
    LPMAPITABLE     lpMsgSvcTable = NULL;   // Table to hold services.
    LPSRowSet       lpSvcRows = NULL;       // Rowset to hold results of table query.
    SPropValue      rgval[2];               // Property structure to hold values we want to set.
    SRestriction    sres;                   // Restriction structure.
    SPropValue      SvcProps;               // Property structure for restriction.
    char            szProfile[80] = {0};    // String for profile name.
    char            szMailbox[80] = {0};    // String for mailbox name.
    char            szServer[80] = {0};     // String for server name.

    // This indicates columns we want returned from HrQueryAllRows.
    enum {iSvcName, iSvcUID, cptaSvc};
    SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_SERVICE_NAME, PR_SERVICE_UID };

    // Get configuration info from user.
    cout<<"Enter name for profile: ";
    cin>>szProfile;
    cout<<"Enter Exchange mailbox name: ";
    cin>>szMailbox;
    cout<<"Enter Exchange server name: ";
    cin>>szServer;

    // Initialize MAPI.

    if (FAILED(hRes = MAPIInitialize(NULL)))
    {
        cout<<"Error initializing MAPI.";
        goto error;
    }

    // Get an IProfAdmin interface.

    if (FAILED(hRes = MAPIAdminProfiles(0,              // Flags.
                                        &lpProfAdmin))) // Pointer to new IProfAdmin.
    {
        cout<<"Error getting IProfAdmin interface.";
        goto error;
    }

    // Create a new profile.

    if (FAILED(hRes = lpProfAdmin->CreateProfile(szProfile,     // Name of new profile.
                                                 NULL,          // Password for profile.
                                                 NULL,          // Handle to parent window.
                                                 NULL)))        // Flags.
    {
        cout<<"Error creating profile.";
        goto error;
    }

    // Get an IMsgServiceAdmin interface off of the IProfAdmin interface.

    if (FAILED(hRes = lpProfAdmin->AdminServices(szProfile,     // Profile that we want to modify.
                                                 NULL,          // Password for that profile.
                                                 NULL,          // Handle to parent window.
                                                 0,             // Flags.
                                                 &lpSvcAdmin))) // Pointer to new IMsgServiceAdmin.
    {
        cout<<"Error getting IMsgServiceAdmin interface.";
        goto error;
    }

    // Create the new message service for Exchange.

    if (FAILED(hRes = lpSvcAdmin->CreateMsgService("MSEMS",     // Name of service from MAPISVC.INF.
                                                   NULL,        // Display name of service.
                                                   NULL,        // Handle to parent window.
                                                   NULL)))      // Flags.
    {
        cout<<"Error creating Exchange message service.";
        goto error;
    }
        
    // You now have to obtain the entry id for the new service.
    // You can do this by getting the message service table
    // and getting the entry that corresponds to the new service.

    if (FAILED(hRes = lpSvcAdmin->GetMsgServiceTable(0,                 // Flags.
                                                     &lpMsgSvcTable)))  // Pointer to table.
    {
        cout<<"Error getting Message Service Table.";
        goto error;
    }

    // Set up restriction to query table.

    sres.rt = RES_CONTENT;
    sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
    sres.res.resContent.ulPropTag = PR_SERVICE_NAME;
    sres.res.resContent.lpProp = &SvcProps;

    SvcProps.ulPropTag = PR_SERVICE_NAME;
    SvcProps.Value.lpszA = "MSEMS";

    // Query the table to obtain the entry for the newly created message service.

    if (FAILED(hRes = HrQueryAllRows(lpMsgSvcTable,
                                     (LPSPropTagArray)&sptCols,
                                     &sres,
                                     NULL,
                                     0,
                                     &lpSvcRows)))
    {
        cout<<"Error querying table for new message service.";
        goto error;
    }

    // Set up a SPropValue array for the properties that you have to configure.

    // First, the server name.
    ZeroMemory(&rgval[1], sizeof(SPropValue) );
    rgval[1].ulPropTag = PR_PROFILE_UNRESOLVED_SERVER;
    rgval[1].Value.lpszA = szServer;

    // Next, the mailbox name.
    ZeroMemory(&rgval[0], sizeof(SPropValue) );
    rgval[0].ulPropTag = PR_PROFILE_UNRESOLVED_NAME; 
    rgval[0].Value.lpszA = szMailbox;

    // Configure the message service by using the previous properties.

        if (FAILED(hRes = lpSvcAdmin->ConfigureMsgService(
        (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb, // Entry ID of service to configure.
        NULL,                                                       // Handle to parent window.
        0,                                                          // Flags.
        2,                                                          // Number of properties we are setting.
        rgval)))                                                    // Pointer to SPropValue array.
    {
        cout<<"Error configuring message service.";
        goto error;
    }

    goto cleanup;

error:
    cout<<" hRes = 0x"<<hex<<hRes<<dec<<endl;
    return FALSE;

cleanup:
    // Clean up.
    if (lpSvcRows) FreeProws(lpSvcRows);
    if (lpMsgSvcTable) lpMsgSvcTable->Release();
    if (lpSvcAdmin) lpSvcAdmin->Release();
    if (lpProfAdmin) lpProfAdmin->Release();

    MAPIUninitialize();
    return TRUE;

}
                

Sample

The following file is available for download from the Microsoft Download Center:

Release Date: October 22, 2001

For more information about how to download Microsoft support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to obtain Microsoft support files from online services


Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file. Profiler.exe is a simple Microsoft Visual C++ sample that illustrates methods 3 through 5 above. The Profiler.exe file contains the following files:

File name Size
Profiler.dsw 1 KB
Profiler.dsp 5 KB
Profiler.cpp 12 KB


Keywords: kbdownload kbhowto kbmsg KB306962