Get file version

Source: Internet
Author: User
GetFileInfo
CUIAction::GetFileVersion2
GetSystemDirectory

    WCHAR szConfigFile[MAX_PATH + 1];
   
::GetSystemDirectory(szConfigFile, MAX_PATH);
  
  ::PathAppend(szConfigFile, FileBootCleanConfigFileName);

void GetApplicationVersion(char * strVersion){TCHAR szFullPath[MAX_PATH]; DWORD dwVerInfoSize = 0; DWORD dwVerHnd; VS_FIXEDFILEINFO * pFileInfo; GetModuleFileName(NULL, szFullPath, sizeof(szFullPath)); dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd); if (dwVerInfoSize) { // If we were able to get the information, process it: HANDLE hMem; LPVOID lpvMem; unsigned int uInfoSize = 0; hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize); lpvMem = GlobalLock(hMem); GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem); ::VerQueryValue(lpvMem, (LPTSTR)("\\"), (void**)&pFileInfo, &uInfoSize); WORD m_nProdVersion[4]; // Product version from the FILEVERSION of the version info resource m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS); m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS); m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS); m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS); sprintf(strVersion, "%d.%d.%d.%d", m_nProdVersion[0], m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]); GlobalUnlock(hMem); GlobalFree(hMem); }else{strcpy(strVersion, "1.0");}}

 

BOOL CModuleVersion::GetDLLVersionInfo(LPCTSTR filename){    m_translation.charset = 1252;    // default = ANSI code page    memset((VS_FIXEDFILEINFO*)this, 0, sizeof(VS_FIXEDFILEINFO));    // get module handle    //HMODULE hModule = LoadLibrary(filename);    //if (hModule==NULL)    //    return FALSE;    // some times, LoadLibrary may fail , --- by bbcallen    HMODULE hModule = LoadLibraryEx(filename, NULL, LOAD_LIBRARY_AS_DATAFILE);    if (hModule==NULL)        return FALSE;    // read file version info    DWORD dwDummyHandle; // will always be set to zero    DWORD len = GetFileVersionInfoSize(filename, &dwDummyHandle);    if (len <= 0)    {        FreeLibrary(hModule);        return FALSE;    }    BYTE* pbData = new BYTE[len]; // allocate version info    if (!pbData)    {        FreeLibrary(hModule);        return FALSE;    }    m_atpVersionInfo.Attach(pbData);    if (!::GetFileVersionInfo(filename, 0, len, m_atpVersionInfo))    {        FreeLibrary(hModule);        return FALSE;    }    LPVOID lpvi;    UINT iLen;    if (!VerQueryValue(m_atpVersionInfo, _T("\\"), &lpvi, &iLen))    {        FreeLibrary(hModule);        return FALSE;    }    // copy fixed info to myself, which am derived from VS_FIXEDFILEINFO    *(VS_FIXEDFILEINFO*)this = *(VS_FIXEDFILEINFO*)lpvi;    // Get translation info    if (VerQueryValue(m_atpVersionInfo,        _T("\\VarFileInfo\\Translation"), &lpvi, &iLen) && iLen >= 4) {        m_translation = *(TRANSLATION*)lpvi;    }    FreeLibrary(hModule);    return dwSignature == VS_FFI_SIGNATURE;}

 

CString CGlobalFun::getIEVersion(){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);  }  }  CString strVersion;strVersion.Format(_T("MSIE %d.%d"),dwMajorVersion,dwMinorVersion);/*printf("mshtml.dll VersionInfo: \n\tMajorVersion=%d\n\tMinorVersion=%d\n\tBuildNumber=%d\n\tRevisionNumber=%d\n",  dwMajorVersion, dwMinorVersion, dwBuildNumber, dwRevisionNumber); */return strVersion;}

 

Hresult cbootchecktool: copydriverifnew (lpcwstr lpsznewdriver) {wchar szolddriver [max_path + 1]; uint uret =: getsystemdirectory (szolddriver, max_path); If (! Uret) return getlasterror ()? Substring (): e_fail;: pathappend (szolddriver, l "drivers");: pathappend (szolddriver, bc_driverfilename); ularge_integer uioldversion = getdllversion (szolddriver ); ularge_integer uinewversion = getdllversion (lpsznewdriver); If (uinewversion. quadpart <= uioldversion. quadpart) return s_false; // do not need to copy // copy the newer version bool BR =: copyfile (lpsznewdriver, szolddriver, false); If (! BR) return getlasterror ()? Destroy (): e_fail; return s_ OK;} ularge_integer cbootchecktool: getdllversion (lpcwstr lpszfilepath) {bool Bret = false; DWORD dwhandle = 0; DWORD dwfileinfosize = 0; vs_fixedfileinfo * pfixfileinfo = NULL; tchar * pszfileinfo = NULL; uint Ulen = 0; ularge_integer uiversion; uiversion. highpart = 0; uiversion. lowpart = 0; dwfileinfosize =: getfileversioninfosize (lpszfilepath, & dwhandl E); If (dwfileinfosize = 0) goto exit0; pszfileinfo = new tchar [dwfileinfosize]; If (pszfileinfo = NULL) goto exit0; Bret =: getfileversioninfo (lpszfilepath, dwhandle, dwfileinfosize, pszfileinfo); If (! Bret) goto exit0; Bret =: verqueryvalue (pszfileinfo, _ T ("\"), (lpvoid *) & pfixfileinfo, & Ulen); If (! Bret) goto exit0; If (Ulen> 0) {uiversion. highpart = pfixfileinfo-> dwfileversionms; uiversion. lowpart = pfixfileinfo-> dwfileversionls;} exit0: If (pszfileinfo) {Delete pszfileinfo; pszfileinfo = NULL;} return uiversion ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.