获取文件版本

GetFileInfoCUIAction::GetFileVersion2GetSystemDirectory

    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() ? 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;
}

获取文件版本,布布扣,bubuko.com

时间: 2024-10-25 11:57:06

获取文件版本的相关文章

C# 获取文件版本

var versionInfo = FileVersionInfo.GetVersionInfo(filePath); String productVersion = versionInfo.ProductVersion; String fileVersion = versionInfo.FileVersion; 其中 productionVersion/fileVersion为右键属性中的产品版本号及文件版本号. 在程序集属性中两者分别对应: [assembly: AssemblyFileVe

VB 获取文件版本

Function GetVer(FilePathName As String) As String If FilePathName = Nothing Or FilePathName = "" Then FilePathName = App.Path & "\" & App.EXEName & ".exe" End If Dim fso As FileSystemObject Set fso = New FileSyste

获取Exe文件版本信息的函数(使用GetFileVersionInfo得到TFileVersionInfo结构体,包含12项内容)

Type   TFileVersionInfo   =   Record         FixedInfo:TVSFixedFileInfo;         {版本信息}         CompanyName:String;                         {公司名称}         FileDescription:String;                 {说明}         FileVersion:String;                      

如何在windows下和linux下获取文件(如exe文件)的详细信息和属性

程序员都很懒,你懂的! 最近在项目开发中,由cs开发的exe的程序,需要自动升级,该exe程序放在linux下,自动升级时检测不到该exe程序的版本号信息,但是我们客户端的exe程序需要获取服务器上新程序的版本号信息.最后由我用java实现linux上exe文件的版本号读取功能.下面是详细代码: package com.herman.utils; import java.io.File; import java.io.FileNotFoundException; import java.io.I

java项目获取文件路径总结

版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] java获取文件路径的方式比较多,总结可能有疏漏. 1.java.lang.System.getProperty(String key) System.getProperty("user.dir")这个方法的作用可以获取当前工程的根目录. ![我的一个项目](http://img.blog.csdn.net/20160322141415562) 比如获取上图中项目的根目录:C:\Users\Administrato

android SDK manager 无法获取更新版本列表【转载】

http://mirrors.neusoft.edu.cn/eclipse/releases/luna/打开这个网址就可以看到adt的详细信息:  http://developer.android.com/sdk/installing/installing-adt.html 或者直接在你的eclipse的Help > Install New Software里面add,地址直接输入 https://dl-ssl.google.com/android/eclipse/https://dl-ssl.

关于svn获取获取文件时 Unable to connect to a repository at URL&quot;https://...&quot;执行上下文错误:参数错误

错误提示: 下面的六种解决方案都未能解决: 1.不提示输入用户名和密码,不管重装多少次都一样. 2.TortoiseSVN的setting->Saved Data->Authentication data 的clear和clear all是灰色的,无法清除 3.用网上说的删除C:\Users\lenovo\AppData\Roaming\Subversion下的所有文件也不行,还是上面图片的错误. 4.用网页登录svn是可以的,也可以输入用户名,密码把我原来存到SVN上的文件下载下来.(网友的

html,图片上传预览,input file获取文件等相关操作

input file常用方法: var obj=document.getElementById("upimage"); var file=obj.files[0];//获取文件数据 var path=obj.value;//获取文件当前路径 var size=obj.files[0].size;//获取文件大小 var prefix=path.substring( path.lastIndexOf('\\')+1 );//获取文件名的前缀名(文件格式) var suffix=path.

Python写自动化之获取文件的MD5值

使用Python 获取文件的MD5 值是一件很简单的事情,Python 提供了md5 和 hashlib 两个模块,都可以获取到文件的md5值. 代码如下: #获取文件的MD5值,适用于小文件 def getFileMD5(self,filepath): if self.isFile(filepath): f = open(filepath,'rb') md5obj = hashlib.md5() md5obj.update(f.read()) hash = md5obj.hexdigest()