• 获取文件版本(IE)


    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: 
    	MajorVersion=%d
    	MinorVersion=%d
    	BuildNumber=%d
    	RevisionNumber=%d
    ",  
    
    		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() ? AtlHresultFromLastError() : 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; // 不需要拷贝
    
    
        // 拷贝较新的版本
        BOOL br = ::CopyFile(lpszNewDriver, szOldDriver, FALSE);
        if (!br)
            return GetLastError() ? AtlHresultFromLastError() : 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, &dwHandle);
        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;
    }
    
  • 相关阅读:
    Go语言学习笔记六--Go语言中for循环的几种用法
    Go语言学习笔记五--时间time的相关处理以及时间格式化
    Windows给妹子修电脑必备装逼命令
    Go语言学习笔记四--基本数据类型与string类型常用方法
    Go语言学习笔记三--const关键字的使用
    Go语言学习笔记二--基本变量的定义与使用
    Go语言学习笔记一
    Linux虚拟机 桥接模式 NAT网络地址转换模式 和仅主机模式的区别
    Java实现邮件发送验证码等信息
    QT 设置菜单图标
  • 原文地址:https://www.cnblogs.com/chunyou128/p/3830512.html
Copyright © 2020-2023  润新知