【转】获取IE版本号
从配置文件获取版本号
#include "windows.h"
#include "Winver.h"
#include "iostream"
#include "tchar.h"
#pragma comment(lib,"Version.lib")
DWORD GetIeVersionFromFile()
{
const TCHAR szFilename[] = _T("mshtml.dll");
DWORD dwMajorVersion = 0, dwMinorVersion = 0;
DWORD dwBuildNumber = 0, dwRevisionNumber = 0;
DWORD dwHandle = 0;
TCHAR szBuf[80];
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);
}
}
else return 0;
wchar_t buf[1024] = { 0 };
wsprintfW(buf, L"IE 版本为 %d.%d.%d.%d", dwMajorVersion, dwMinorVersion, dwBuildNumber, dwRevisionNumber);
OutputDebugStringW(buf);
return dwMajorVersion;//返回主版本号
}
从注册表获取版本号
BOOL GetRegQueryValue(HKEY hKey, LPCTSTR lpSubKey,LPCTSTR lpValueName, LPTSTR szQueryValue) { HKEY hResult; LONG nResult; BOOL b64OS = OSVersion::Is64BitOs(); if( b64OS == TRUE ) { nResult = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ|KEY_WOW64_64KEY, &hResult); } else { nResult = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ|KEY_WOW64_32KEY, &hResult); } if(ERROR_SUCCESS != nResult) { return FALSE; } DWORD lValueSize = 256, dwType = REG_SZ; nResult = RegQueryValueEx(hResult, lpValueName, NULL, &dwType, (LPBYTE)szQueryValue, &lValueSize); if(ERROR_SUCCESS != nResult) { RegCloseKey(hResult); return FALSE; } RegCloseKey(hResult); return TRUE; } CString GetIeVersionFromReg() { CString strIeVersion; CString strRegPath = _T("SOFTWARE\\Microsoft\\Internet Explorer"); TCHAR szVersion[256] = {0}; if( GetRegQueryValue(HKEY_LOCAL_MACHINE, strRegPath, _T("svcVersion"), (LPTSTR)szVersion )) { strIeVersion = szVersion; } else if( GetRegQueryValue(HKEY_LOCAL_MACHINE, strRegPath, _T("Version"), (LPTSTR)szVersion )) { strIeVersion = szVersion; } else { strIeVersion = GetIeVersionFromFile(); } return strIeVersion; }