Export (0) Print
Expand All
Expand Minimize

How to: Detect the Version of Exchange Server in an Outlook Profile

Office 2007

This topic includes a code sample in C++ that shows how to use the PR_PROFILE_SERVER_VERSION property and PR_PROFILE_SERVER_FULL_VERSION property to obtain version information of the Microsoft Exchange Server that the active account is connected to.

The GetProfileServiceVersion function in the code sample accepts a profile as an input parameter. Depending on whether the PR_PROFILE_SERVER_VERSION property and the PR_PROFILE_SERVER_FULL_VERSION property exist in the given profile, the function gets each property and returns the appropriate version information as output parameters.

GetProfileServiceVersion first calls the MAPIAdminProfiles function to create a profile administration object. It then uses the profile administration object to call IProfAdmin::AdminServices to obtain a message service administration object. Using the message service administration object, it calls IMsgServiceAdmin::OpenProfileSection to obtain a section of the current profile, and then calls HrGetOneProp to verify if each of the two properties exists in that section of the profile, and if so, sets the version information in the appropriate output parameters.

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 any server version was found, consider the call a success
    if (*lpbFoundServerVersion || *lpbFoundServerFullVersion) hRes = S_OK;
	
    return hRes;
}


Community Additions

ADD
Show:
© 2014 Microsoft