C++语言 获取EXE文件的属性详细信息

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

转载于:https://www.cnblogs.com/pythonschool/archive/2012/11/10/2764517.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值