程序中使用IE的WebBrowser 控件(MSHTML)或者开发BHO插件的时候,通常需要获得IE的版本号以便做不同处理。这里介绍2中获得IE版本号的方法:
1) 通过注册表
IE的版本号信息放在注册表的:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version
注:64位机器的32位IE在 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Version
2) 通过读取mshtml.dll 的版本号
mshtml是IE的核心DLL之一。 mshtml.dll文件的版本号码和IE的版本号码应该是一致的。以下代码演示如何获得mshtml.dll的版本号。
view plaincopy to clipboardprint?
const TCHAR szFilename[] = _T("mshtml.dll");
DWORD dwMajorVersion =0, dwMinorVersion = 0;
DWORD dwBuildNumber =0, dwRevisionNumber = 0;
DWORD dwHandle = 0;
DWORD dwVerInfoSize = GetFileVersionInfoSize(szFilename, &dwHandle);
if (dwVerInfoSize)
{
LPVOID lpBuffer = LocalAlloc(LPTR, dwVerInfoSize);
if (lpBuffer)
{
if (GetFileVersionInfo(szFilename, dwHandle, dwVerInfoSize, lpBuffer))
{
VS_FIXEDFILEINFO * lpFixedFileInfo = NULL;
UINT nFixedFileInfoSize = 0;
if (VerQueryValue(lpBuffer, TEXT("\\"), (LPVOID*)&lpFixedFileInfo, &nFixedFileInfoSize) &&(nFixedFileInfoSize))
{
dwMajorVersion = HIWORD(lpFixedFileInfo->dwFileVersionMS);
dwMinorVersion = LOWORD(lpFixedFileInfo->dwFileVersionMS);
dwBuildNumber = HIWORD(lpFixedFileInfo->dwFileVersionLS);
dwRevisionNumber = LOWORD(lpFixedFileInfo->dwFileVersionLS);
}
}
LocalFree(lpBuffer);
}
}
printf("mshtml.dll VersionInfo: \n\tMajorVersion=%d\n\tMinorVersion=%d\n\tBuildNumber=%d\n\tRevisionNumber=%d\n",
dwMajorVersion, dwMinorVersion, dwBuildNumber, dwRevisionNumber);
const TCHAR szFilename[] = _T("mshtml.dll");
DWORD dwMajorVersion =0, dwMinorVersion = 0;
DWORD dwBuildNumber =0, dwRevisionNumber = 0;
DWORD dwHandle = 0;
DWORD dwVerInfoSize = GetFileVersionInfoSize(szFilename, &dwHandle);
if (dwVerInfoSize)
{
LPVOID lpBuffer = LocalAlloc(LPTR, dwVerInfoSize);
if (lpBuffer)
{
if (GetFileVersionInfo(szFilename, dwHandle, dwVerInfoSize, lpBuffer))
{
VS_FIXEDFILEINFO * lpFixedFileInfo = NULL;
UINT nFixedFileInfoSize = 0;
if (VerQueryValue(lpBuffer, TEXT("\\"), (LPVOID*)&lpFixedFileInfo, &nFixedFileInfoSize) &&(nFixedFileInfoSize))
{
dwMajorVersion = HIWORD(lpFixedFileInfo->dwFileVersionMS);
dwMinorVersion = LOWORD(lpFixedFileInfo->dwFileVersionMS);
dwBuildNumber = HIWORD(lpFixedFileInfo->dwFileVersionLS);
dwRevisionNumber = LOWORD(lpFixedFileInfo->dwFileVersionLS);
}
}
LocalFree(lpBuffer);
}
}
printf("mshtml.dll VersionInfo: \n\tMajorVersion=%d\n\tMinorVersion=%d\n\tBuildNumber=%d\n\tRevisionNumber=%d\n",
dwMajorVersion, dwMinorVersion, dwBuildNumber, dwRevisionNumber);
const TCHAR szFilename[] = _T("mshtml.dll");
DWORD dwMajorVersion =0, dwMinorVersion = 0;
DWORD dwBuildNumber =0, dwRevisionNumber = 0;
DWORD dwHandle = 0;
DWORD dwVerInfoSize = GetFileVersionInfoSize(szFilename, &dwHandle);
if (dwVerInfoSize)
{
LPVOID lpBuffer = LocalAlloc(LPTR, dwVerInfoSize);
if (lpBuffer)
{
if (GetFileVersionInfo(szFilename, dwHandle, dwVerInfoSize, lpBuffer))
{
VS_FIXEDFILEINFO * lpFixedFileInfo = NULL;
UINT nFixedFileInfoSize = 0;
if (VerQueryValue(lpBuffer, TEXT("\\"), (LPVOID*)&lpFixedFileInfo, &nFixedFileInfoSize) &&(nFixedFileInfoSize))
{
dwMajorVersion = HIWORD(lpFixedFileInfo->dwFileVersionMS);
dwMinorVersion = LOWORD(lpFixedFileInfo->dwFileVersionMS);
dwBuildNumber = HIWORD(lpFixedFileInfo->dwFileVersionLS);
dwRevisionNumber = LOWORD(lpFixedFileInfo->dwFileVersionLS);
}
}
LocalFree(lpBuffer);
}
}
printf("mshtml.dll VersionInfo: \n\tMajorVersion=%d\n\tMinorVersion=%d\n\tBuildNumber=%d\n\tRevisionNumber=%d\n",
dwMajorVersion, dwMinorVersion, dwBuildNumber, dwRevisionNumber);
const TCHAR szFilename[] = _T("mshtml.dll");
DWORD dwMajorVersion =0, dwMinorVersion = 0;
DWORD dwBuildNumber =0, dwRevisionNumber = 0;
DWORD dwHandle = 0;
DWORD dwVerInfoSize = GetFileVersionInfoSize(szFilename, &dwHandle);
if (dwVerInfoSize)
{
LPVOID lpBuffer = LocalAlloc(LPTR, dwVerInfoSize);
if (lpBuffer)
{
if (GetFileVersionInfo(szFilename, dwHandle, dwVerInfoSize, lpBuffer))
{
VS_FIXEDFILEINFO * lpFixedFileInfo = NULL;
UINT nFixedFileInfoSize = 0;
if (VerQueryValue(lpBuffer, TEXT("\\"), (LPVOID*)&lpFixedFileInfo, &nFixedFileInfoSize) &&(nFixedFileInfoSize))
{
dwMajorVersion = HIWORD(lpFixedFileInfo->dwFileVersionMS);
dwMinorVersion = LOWORD(lpFixedFileInfo->dwFileVersionMS);
dwBuildNumber = HIWORD(lpFixedFileInfo->dwFileVersionLS);
dwRevisionNumber = LOWORD(lpFixedFileInfo->dwFileVersionLS);
}
}
LocalFree(lpBuffer);
}
}
printf("mshtml.dll VersionInfo: \n\tMajorVersion=%d\n\tMinorVersion=%d\n\tBuildNumber=%d\n\tRevisionNumber=%d\n",
dwMajorVersion, dwMinorVersion, dwBuildNumber, dwRevisionNumber);
通过以上2种方法获得 MajorVersion, MinorVersion, BuildNumber, RevisionNumber 之后,你可以查询我之前的blog文章 《IE 版本号大全》里面的那个表来判断是那个IE发行版本。
相关Blog文章:
本文转自 陈本峰 51CTO博客,原文链接:http://blog.51cto.com/wingeek/273689,如需转载请自行联系原作者