HOWTO: Open the Global Profile Section

ID: Q188482

The information in this article applies to:

SUMMARY

This article provides code that demonstrates how to open the Global Profile Section and retrieve one of the properties that exist in this section. It also provides a comprehensive list of properties that exist in the global profile section. The key to this is to request the profile section that has pbGlobalProfileSectionGuid for its unique identifier. This is a constant that is defined in the Edkmdb.h file.

MORE INFORMATION

It may be necessary to retrieve or modify the values of properties that exist in the Global Profile Section of a Messaging Application Programming Interface (MAPI) profile. A global profile section exists for each profile that uses the Microsoft Exchange Messaging Service. This "global section" is used to store common data, plus individual sections for the transport provider, one store provider for the user, one store provider for the public store, and one store provider for each additional mailbox to which the user has delegate access.

The following code is an example of how to open the Global Profile Section of a MAPI profile and how to extract the PR_PROFILE_HOME_SERVER property:

Sample Code

   #include <objbase.h>
   #include <mapix.h>
   #include <mapidefs.h>
   #include <mapiguid.h>
   #include <edk.h>
   #include <edkmdb.h>

   HRESULT GetServerName()
   {
     HRESULT hRes = S_OK;   // HRESULT returned by this method
     LPPROFADMIN pAdminProfiles = NULL; // Pointer to IProfAdmin object
     LPSERVICEADMIN pSvcAdmin = NULL;  // Pointer to IServiceAdmin object
     LPPROFSECT pGlobalProfSect = NULL; // Pointer to IProfSect object
     LPSPropValue pProps = NULL; // Pointer to PropValue
                                // PR_PROFILE_HOME_SERVER
     char szServerName[256]; // String that will contain the server name
     // If your app doesn't already initialize the MAPI subsystem,
     // do it now.
     if ( FAILED ( hRes = MAPIInitialize ( NULL ) ) )
        return hRes;

     // Get a Profile admin object
     if ( FAILED ( hRes = MAPIAdminProfiles ( 0L, &pAdminProfiles ) ) )
        goto CleanUp;

     // Get a ServiceAdmin object
     if ( FAILED ( hRes = pAdminProfiles -> AdminServices (
                                           "<profile name>",
                                           NULL,
                                           0L,  // Your app's window handle
                                           0L,
                                           &pSvcAdmin ) ) )
       goto CleanUp;

      // Get the Global Profile Section by calling
      // IServiceAdmin::OpenProfileSection use pbGlobalProfileSectionGuid
      // defined in EDKMDB.H as the entry ID to request
      // The default return is an IProfSect interface.
      if ( FAILED ( hRes = pSvcAdmin -> OpenProfileSection (
                                  (LPMAPIUID)pbGlobalProfileSectionGuid,
                                  NULL,
                                  0L,
                                  &pGlobalProfSect ) ) )
         goto CleanUp;

      // Call HrGetOneProp to get PR_PROFILE_HOME_SERVER
      if ( FAILED ( hRes = HrGetOneProp ( pGlobalProfSect,
                                          PR_PROFILE_HOME_SERVER,
                                          &pProps ) ) )
         goto CleanUp;

      // Set Server name pointer to string equal to value returned from
      // HrGetOneProp
      strcpy ( szServerName, "PR_PROFILE_HOME_SERVER == " );
      strcat ( szServerName, pProps -> Value.lpszA );

      // Replace window handle param with your application's window handle
      MessageBox ( 0L, szServerName, "Exchange Server Name", MB_OK );

      CleanUp:

      // Free all memory allocated by any MAPI calls

      if ( NULL != pAdminProfiles )
         pAdminProfiles -> Release ();

      if ( NULL != pSvcAdmin )
         pSvcAdmin -> Release ( );

      if ( NULL != pGlobalProfSect )
         pGlobalProfSect -> Release ( );

      if ( NULL != pProps )
         MAPIFreeBuffer ( &pProps );

      pSvcAdmin = NULL;
      pGlobalProfSect = NULL;
      pProps = NULL;
      pAdminProfiles = NULL;

      // Return the HRESULT to the calling function
      return hRes;
      }

NOTE: Be sure to include the following libraries in the link process:

   Kernel32.lib, User32.lib, Msvcrt.lib, Mapi32.lib, Edkguid.lib,
   Edkutils.lib, Edkmapi.lib, Edkdebug.lib.

You also need to check the option to ignore default libraries in the general project settings of the link process. To do this, choose Settings from the Project menu, click the Link tab, set the category box to General and than select the desired option.

The following is a list of properties that exist in the Global Profile Section:

Please read the Platform Software Developers Kit for more information on these and other properties.

Additional query words: kbDSupport kbMsg kbEDK kbEDK400 kbEDK500 kbMAPI100 kbMAPI EDKAPI EMAPI

Keywords          : kbAPI kbEDK kbMsg kbMAPI100 
Version           : WINDOWS:1.0,4.0,5.0
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: July 1, 1998