C++语言 获取EXE文件的属性详细信息
2012-11-10 22:09
381 查看
////////////////////////////////////////////////////////////// // // File: getfileversion.cpp // Description: 获取EXE文件的属性详细信息 // Created: 2012-10-18 // Author:pythonschool.com // ////////////////////////////////////////////////////////////// /* The following code shows how to get FILEINFO value from resource file. These WIN32 functions will be used: * GetFileVersionInfo * GetFileVersionInfoSize * VerQueryValue * GetModuleFileName */ #include "stdafx.h" #include <windows.h> #include <tchar.h> #include <string> #include <iostream> #include "stdio.h" #pragma comment(lib, "version.lib") using namespace std; std::string GetFileVersion(char * strFilePath) { DWORD dwSize; DWORD dwRtn; std::string szVersion; //获取版本信息大小 dwSize = GetFileVersionInfoSize(strFilePath,NULL); if (dwSize == 0) { return ""; } char *pBuf; pBuf= new char[dwSize + 1]; if(pBuf == NULL) return ""; memset(pBuf, 0, dwSize + 1); //获取版本信息 dwRtn = GetFileVersionInfo(strFilePath,NULL, dwSize, pBuf); if(dwRtn == 0) { return ""; } LPVOID lpBuffer = NULL; UINT uLen = 0; //版本资源中获取信息 dwRtn = VerQueryValue(pBuf, TEXT("\\StringFileInfo\\080404b0\\FileDescription"), //0804中文 //04b0即1252,ANSI //可以从ResourceView中的Version中BlockHeader中看到 //可以测试的属性 /* CompanyName FileDescription FileVersion InternalName LegalCopyright OriginalFilename ProductName ProductVersion Comments LegalTrademarks PrivateBuild SpecialBuild */ &lpBuffer, &uLen); if(dwRtn == 0) { return ""; } szVersion = (char*)lpBuffer; delete pBuf; return szVersion; } void main() { #define MY_BUFSIZE 500 HKEY hKey; TCHAR szProductType[MY_BUFSIZE]; DWORD dwBufLen = MY_BUFSIZE; LONG lRet; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Tencent\\PlatForm_Type_List\\3"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { lRet = RegQueryValueEx(hKey, TEXT("TypePath"), NULL, NULL, (LPBYTE)szProductType, &dwBufLen); //return szProductType; } RegCloseKey(hKey); //char * strFilePath = "C:\\Program Files\\Tencent\\QQ\\Bin\\QQ.exe"; char * strFilePath = szProductType; cout << strFilePath << " FileDescription is: " << GetFileVersion(strFilePath) << endl; getchar(); }
相关文章推荐
- 如何在windows下和linux下获取文件(如exe文件)的详细信息和属性
- 使用ShellClass获取文件属性详细信息
- vc++读取文件属性的详细信息描述 通过读取QQ的注册表和EXE路径两种方式
- VerQueryValue获取文件-属性-详细信息
- 如何在跨平台的情况下获取可执行文件的详细信息和属性
- 获取文件属性中详细信息里的各项目(vb 学习备注)
- 使用ShellClass获取文件属性详细信息的实现方法
- 使用ShellClass获取文件属性详细信息
- 利用stat命令获取Linux文件系统和文件的详细状态信息
- FileInfo 0.0.0003--masm32写的获取文件属性、版本、时间、MD5值等信息的小程序
- 利用反射获取.DLL文件中的属性和方法以及版本信息
- 【dumpe2fs】显示文件系统属性信息(更加详细)
- linux stat函数(获取文件详细信息)
- php学习读取视频文件来获取视频属性的信息
- shell32 获取文件(MP3)详细信息
- IOS开发——获取本地音频文件(属性/信息)
- HDFS——如何获取文件的属性信息
- 【java常见问题】——如何获取文件的属性信息?
- IOS开发——获取本地音频文件(属性/信息)
- 获取dataview显示的文件的详细信息