Detecting the Version Of Exchange in a Profile

[This is now documented here: https://msdn2.microsoft.com/en-us/library/bb820967.aspx]

We had some folks asking recently if there's a property in the profile you can use to determine what version of Exchange the mailbox in the profile is on. It turns out there is, but it's not guaranteed to be there, and it changes in Outlook 2007.

First, the pre-Outlook 2007 property: The version of emsmdb32.dll that comes with Outlook 2003 and earlier and with all of Exchange's implementations of MAPI will write the property PR_PROFILE_SERVER_VERSION into the global profile section of the profile. This property was previously discussed in Jason's blog posting on GC Reconnect. This property is a PT_LONG, and will typically contain partial information about the build of the Exchange server. However, the data contained in this property is not encoded consistently between different versions of Exchange.

For instance, against my test Exchange 2003 server, I see this property contains 6944 decimal - the version of store.exe on this server is 6.5.6944.3. Against my test Exchange 2007 server, I see the property contains 33453 decimal, which is 0x82AD hex. 0x2AD hex is 685 decimal. The version of store on my test Exchange 2007 server is 8.0.685.24, so we see the major version and build numbers were encoded in the property.

The developers of Outlook 2007 wanted more granularity out of the version. The conversation emsmdb32 conducts with the Exchange server actually contains the full version information. But that's too much to stick in a PT_LONG. So they created a new property, PR_PROFILE_SERVER_FULL_VERSION, which is a PT_BINARY. This allows us to store a EXCHANGE_STORE_VERSION_NUM structure with both the major and minor version numbers and the major and minor build numbers (note: this is the same format used by PR_REPLICA_VERSION). When we look at an Outlook 2007 profile connecting to the above servers, we see the full version information is available.

Some comments:

  • There's no guarantee you'll find these properties in a profile. If they're there, emsmdb32 can use them to make some decisions during connection (such as noted in Jason's blog). However, regardless of what's in them, when emsmdb32 connects to the Exchange server, it will rewrite them. Note that after applying a hotfix to the Exchange server you'll probably see these numbers bump up on subsequent connections.
  • Only one of these properties is likely to be in a profile. Outlook 2007 no longer reads or writes PR_PROFILE_SERVER_VERSION. I haven't tested the upgrade scenario, so if you're writing code to check these properties, you should check PR_PROFILE_SERVER_FULL_VERSION first.
  • These properties are of no help in detecting whether or not it's safe to pass CONNECT_IGNORE_NO_PF. They don't get written until after a successful connection, and if you need CONNECT_IGNORE_NO_PF, you won't connect successfully until it's set. Catch-22.
  • If you're using the Outlook 2007 object model, you may want to look at NameSpace.ExchangeMailboxServerVersion.

Here's a function I wrote to demonstrate how to fetch these properties:

 #define PR_PROFILE_SERVER_VERSION      PROP_TAG( PT_LONG, 0x661B)
#define PR_PROFILE_SERVER_FULL_VERSION PROP_TAG( PT_BINARY, 0x663B)

typedef struct
{
    WORD    wMajorVersion;
  WORD    wMinorVersion;
  WORD    wBuild;
 WORD    wMinorBuild;
} EXCHANGE_STORE_VERSION_NUM;

HRESULT GetProfileServiceVersion(LPSTR lpszProfileName,
                                 ULONG* lpulServerVersion,
                               WORD* lpwMajorVersion,
                              WORD* lpwMinorVersion,
                              WORD* lpwBuild,
                                 WORD* lpwMinorBuild,
                                BOOL* lpbFoundServerVersion,
                                BOOL* lpbFoundServerFullVersion)
{
  if (!lpszProfileName 
       || !lpulServerVersion
       || !lpwMajorVersion
     || !lpwMinorVersion
     || !lpwBuild
        || !lpwMinorBuild
       || !lpbFoundServerVersion
       || !lpbFoundServerFullVersion) return MAPI_E_INVALID_PARAMETER;
 *lpbFoundServerVersion = false;
 *lpbFoundServerFullVersion = false;
 
    HRESULT        hRes= S_OK;
  LPPROFADMIN    lpProfAdmin = NULL;
  LPSERVICEADMIN lpServiceAdmin = NULL;
   
    hRes = MAPIAdminProfiles(0, &lpProfAdmin);
  if (!lpProfAdmin) return hRes;
  
    hRes = lpProfAdmin->AdminServices(
       (LPTSTR)lpszProfileName,
        _T(""), 
      0,
      0,
      &lpServiceAdmin);
   
    if (lpServiceAdmin)
 {
       LPPROFSECT lpProfSect = NULL;
       hRes = lpServiceAdmin->OpenProfileSection(
           (LPMAPIUID)pbGlobalProfileSectionGuid,
          NULL,
           0,
          &lpProfSect);
       if (lpProfSect)
     {
           LPSPropValue lpServerVersion = NULL;
            hRes = HrGetOneProp(lpProfSect,PR_PROFILE_SERVER_VERSION,&lpServerVersion);
         
            if (SUCCEEDED(hRes) && lpServerVersion && PR_PROFILE_SERVER_VERSION == lpServerVersion->ulPropTag)
           {
               *lpbFoundServerVersion = true;
              *lpulServerVersion = lpServerVersion->Value.l;
           }
           MAPIFreeBuffer(lpServerVersion);
            
            LPSPropValue lpServerFullVersion = NULL;
            hRes = HrGetOneProp(lpProfSect,PR_PROFILE_SERVER_FULL_VERSION,&lpServerFullVersion);
            
            if (SUCCEEDED(hRes) && 
             lpServerFullVersion && 
             PR_PROFILE_SERVER_FULL_VERSION == lpServerFullVersion->ulPropTag)
            {
               if (lpServerFullVersion->Value.bin.cb == sizeof(EXCHANGE_STORE_VERSION_NUM))
             {
                   EXCHANGE_STORE_VERSION_NUM* lpStoreVersion = 
                       (EXCHANGE_STORE_VERSION_NUM*)(lpServerFullVersion->Value.bin.lpb);
                   
                    *lpbFoundServerFullVersion = true;
                  *lpwMajorVersion = lpStoreVersion->wMajorVersion;
                    *lpwMinorVersion = lpStoreVersion->wMinorVersion;
                    *lpwBuild = lpStoreVersion->wBuild;
                  *lpwMinorBuild = lpStoreVersion->wMinorBuild;
                }
           }
           MAPIFreeBuffer(lpServerFullVersion);
            
            lpProfSect->Release();
       }
       lpServiceAdmin->Release();
   }
   
    lpProfAdmin->Release();
  
    // If we found any server version, consider the call a success
  if (*lpbFoundServerVersion || *lpbFoundServerFullVersion) hRes = S_OK;
  
    return hRes;
}