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;
}
Comments
Anonymous
July 17, 2007
Hello Stephen, I got the PR_PROFILE_SERVER_VERSION property, as described by you, for both Exchange 2003 and Exchange 2007 Servers. For 2003 Server i got the version# as: 0x1DE4 (decimal 7652) For 2007 Server i got the version# as: 0x82AD (decimal 33453) Now, the other way around: Given the numbers, how do i make out what what version of the server am i connecting to? Do i have to hard code these values and map them?Anonymous
July 17, 2007
Apropos my last comment, i could not retrieve the PR_PROFILE_SERVER_FULL_VERSION property for either of the servers (got "MAPI_E_NOT_FOUND" error)Anonymous
July 18, 2007
>Do i have to hard code these values and map them? Pretty much - that's why I didn't include code for parsing them. :) PR_PROFILE_SERVER_FULL_VERSION should only be in profiles created/used by Outlook 2007 - the server is irrelevent. Apologies if I didn't make that clear.Anonymous
July 18, 2007
Thanks a lot Stephen, that was really helpful.Anonymous
November 30, 2010
This is a great sample. Thanks! How does this function with Outlook 2010, where you can have multiple Exchange message stores in a profile? Which Exchange server version is stored in these properties? Or is this whole structure obsolete in Outlook 2010?Anonymous
November 30, 2010
For multiex, pbGlobalProfileSectionGuid will open the profile section for the primary mailbox. For other mailboxes, you'll need to open the appropriate profile section (see multi-ex docs) then the property will give the version for that server.Anonymous
May 06, 2014
You mention that PR_REPLICA_VERSION uses the same format. This may be true up to Exchange 2007. Looking at Exchange 2010 or 2013, I cannot map the property to a version number.
- for Version 15.0 (Build 775.38), I see hex F00000583070FB6 which would be version 3840.5.33543.4022
- for Version 15.0 (Build 847.32), I see hex 8030005815C0001 which would be version 2051.5.33116.1
- for 2010 SP3 RU 5 (according to programs/features - EMC and EMS show Version 14.3 (Build 123.4), I see hex E03000580B50FA6 which would be 3587.5.32949.4006 Can you shed some light?