How to: Check the Version of Outlook
This topic shows a code sample that checks version information of an installed version of Microsoft Outlook, if the installed version is Microsoft Outlook 2010, Microsoft Office Outlook 2007, or Microsoft Office Outlook 2003. Checking the version of Outlook is sometimes necessary to ensure that a MAPI application calls API elements that are supported by the currently running version of Outlook.
The following code sample, GetOutlookVersionString, obtains the full version string by using the MsiProvideQualifiedComponent and MsiGetFileVersion functions, as declared in the Msi.h file in the Microsoft Windows Software Development Kit (SDK). GetOutlookVersionString also returns a pointer to a Boolean variable that indicates whether a 64-bit version of Outlook is installed. For information about the expected values for the different parts of a version string for some released versions of Outlook, see How to determine Outlook version information.
HRESULT GetOutlookVersionString(LPSTR* ppszVer, BOOL* pf64Bit)
{
HRESULT hr = E_FAIL;
LPSTR pszTempPath = NULL;
LPSTR pszTempVer = NULL;
TCHAR pszaOutlookQualifiedComponents[][MAX_PATH] = {
TEXT("{1E77DE88-BCAB-4C37-B9E5-073AF52DFD7A}"), // Outlook 2010
TEXT("{24AAE126-0911-478F-A019-07B875EB9996}"), // Outlook 2007
TEXT("{BC174BAD-2F53-4855-A1D5-0D575C19B1EA}") // Outlook 2003
};
int nOutlookQualifiedComponents = _countof(pszaOutlookQualifiedComponents);
int i = 0;
DWORD dwValueBuf = 0;
UINT ret = 0;
*pf64Bit = FALSE;
for (i = 0; i < nOutlookQualifiedComponents; i++)
{
ret = MsiProvideQualifiedComponent(
pszaOutlookQualifiedComponents[i],
TEXT("outlook.x64.exe"),
(DWORD) INSTALLMODE_DEFAULT,
NULL,
&dwValueBuf);
if (ERROR_SUCCESS == ret) break;
}
if (ret != ERROR_SUCCESS)
{
ret = MsiProvideQualifiedComponent(
pszaOutlookQualifiedComponents[i],
TEXT("outlook.exe"),
(DWORD) INSTALLMODE_DEFAULT,
NULL,
&dwValueBuf);
}
else
{
*pf64Bit = TRUE;
}
if (ret == ERROR_SUCCESS)
{
dwValueBuf += 1;
pszTempPath = (LPSTR) malloc(dwValueBuf * sizeof(TCHAR));
if (pszTempPath != NULL)
{
if ((ret = MsiProvideQualifiedComponent(
pszaOutlookQualifiedComponents[i],
TEXT("outlook.exe"),
(DWORD) INSTALLMODE_EXISTING,
pszTempPath,
&dwValueBuf)) != ERROR_SUCCESS)
{
goto Error;
}
pszTempVer = (LPSTR) malloc(MAX_PATH * sizeof(TCHAR));
dwValueBuf = MAX_PATH;
if ((ret = MsiGetFileVersion(pszTempPath,
pszTempVer,
&dwValueBuf,
NULL,
NULL))!= ERROR_SUCCESS)
{
goto Error;
}
*ppszVer = pszTempVer;
pszTempVer = NULL;
hr = S_OK;
}
}
Error:
free(pszTempVer);
free(pszTempPath);
return hr;
}
See Also
I needed this in VB.NET so I wrote this function. Has worked great for so far.
Public Function GetOutlookVersion()
GetOutlookVersion = 0
' Get path to outlook from registry
Dim sOutlookPath As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", "Path", Nothing)
If Not sOutlookPath Is Nothing Then
Dim sOutlookVersion As FileVersionInfo = FileVersionInfo.GetVersionInfo(sOutlookPath & "\outlook.exe")
GetOutlookVersion = Left(sOutlookVersion.FileVersion, 2)
End If
End Function
- 1/27/2011
- Paul.Jones
- 1/27/2011
- Paul.Jones
HRESULT GetOutlookVersionString(LPTSTR* ppszVer, BOOL* pf64Bit)
{
HRESULT hr = E_FAIL;
LPTSTR pszTempPath = NULL;
LPTSTR pszTempVer = NULL;
TCHAR pszaOutlookQualifiedComponents[][MAX_PATH] = {
TEXT("{1E77DE88-BCAB-4C37-B9E5-073AF52DFD7A}"), // Outlook 2010
TEXT("{24AAE126-0911-478F-A019-07B875EB9996}"), // Outlook 2007
TEXT("{BC174BAD-2F53-4855-A1D5-0D575C19B1EA}") // Outlook 2003
};
int nOutlookQualifiedComponents = sizeof(pszaOutlookQualifiedComponents)/(MAX_PATH*sizeof(TCHAR)); //Changed
int i = 0;
DWORD dwValueBuf = 0;
UINT ret = 0;
*pf64Bit = FALSE;
for (i = 0; i < nOutlookQualifiedComponents; i++)
{
ret = MsiProvideQualifiedComponent(
pszaOutlookQualifiedComponents[i],
TEXT("outlook.x64.exe"),
(DWORD) INSTALLMODE_DEFAULT,
NULL,
&dwValueBuf);
if (ERROR_SUCCESS == ret) break;
}
if (ret != ERROR_SUCCESS)
{
for (i = 0; i < nOutlookQualifiedComponents; i++) //Added
{
ret = MsiProvideQualifiedComponent(
pszaOutlookQualifiedComponents[i],
TEXT("outlook.exe"),
(DWORD) INSTALLMODE_DEFAULT,
NULL,
&dwValueBuf);
if (ERROR_SUCCESS == ret) break; //Added
}
}
else
{
*pf64Bit = TRUE;
}
if (ret == ERROR_SUCCESS)
{
dwValueBuf += 1;
pszTempPath = (LPTSTR) malloc(dwValueBuf * sizeof(TCHAR));
if (pszTempPath != NULL)
{
if ((ret = MsiProvideQualifiedComponent(
pszaOutlookQualifiedComponents[i],
TEXT("outlook.exe"),
(DWORD) INSTALLMODE_EXISTING,
pszTempPath,
&dwValueBuf)) != ERROR_SUCCESS)
{
goto Error;
}
pszTempVer = (LPTSTR) malloc(MAX_PATH * sizeof(TCHAR));
dwValueBuf = MAX_PATH;
if ((ret = MsiGetFileVersion(pszTempPath,
pszTempVer,
&dwValueBuf,
NULL,
NULL))!= ERROR_SUCCESS)
{
goto Error;
}
*ppszVer = pszTempVer;
pszTempVer = NULL;
hr = S_OK;
}
}
Error:
free(pszTempVer);
free(pszTempPath);
return hr;
}
And do not forget to add Msi.lib in your project.
- 8/17/2010
- Erdogan Camcioglu