获取文件版本信息

REF : http://blog.youkuaiyun.com/sysprogram/article/details/6935214


  1. char*   szFileName   =   "C:\\windows\\system32\\cmd.exe";   
  2. DWORD   dwSize   =   GetFileVersionInfoSize(szFileName,NULL);   
  3. LPVOID   pBlock   =   malloc(dwSize);   
  4. GetFileVersionInfo(szFileName,0,dwSize,pBlock);   
  5.   
  6. char*   pVerValue   =   NULL;   
  7. UINT   nSize   =   0;   
  8. VerQueryValue(pBlock,TEXT( "\\VarFileInfo\\Translation"),   
  9.     (LPVOID*)&pVerValue,&nSize);   
  10.   
  11. CString   strSubBlock,strTranslation,strTemp;   
  12.   
  13. strTemp.Format( "000%x",*((unsigned   short   int   *)pVerValue));   
  14. strTranslation   =   strTemp.Right(4);   
  15. strTemp.Format( "000%x",*((unsigned   short   int   *)&pVerValue[2]));   
  16. strTranslation   +=   strTemp.Right(4);   
  17. //080404b0为中文,040904E4为英文   
  18.   
  19. MessageBox(strTranslation);  
  20.   
  21. //文件描述   
  22. strSubBlock.Format("\\StringFileInfo\\%s\\FileDescription",strTranslation);   
  23. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  24. strSubBlock.ReleaseBuffer();   
  25. strTemp.Format( "文件描述:   %s ",pVerValue);   
  26. AfxMessageBox(strTemp);   
  27.   
  28. //内部名称   
  29. strSubBlock.Format("\\StringFileInfo\\%s\\InternalName",strTranslation);   
  30. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  31. strSubBlock.ReleaseBuffer();   
  32. strTemp.Format( "内部名称:   %s ",pVerValue);   
  33. AfxMessageBox(strTemp);   
  34.   
  35. //合法版权   
  36. strSubBlock.Format("\\StringFileInfo\\%s\\LegalTradeMarks",strTranslation);   
  37. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  38. strSubBlock.ReleaseBuffer();   
  39. strTemp.Format( "合法版权:   %s ",pVerValue);   
  40. AfxMessageBox(strTemp);   
  41.   
  42. //原始文件名   
  43. strSubBlock.Format("\\StringFileInfo\\%s\\OriginalFileName",strTranslation);   
  44. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  45. strSubBlock.ReleaseBuffer();   
  46. strTemp.Format( "原始文件名:   %s ",pVerValue);   
  47. AfxMessageBox(strTemp);   
  48.   
  49. //产品名称   
  50. strSubBlock.Format("\\StringFileInfo\\%s\\ProductName",strTranslation);   
  51. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  52. strSubBlock.ReleaseBuffer();   
  53. strTemp.Format("产品名称:   %s ",pVerValue);   
  54. AfxMessageBox(strTemp);   
  55.   
  56. //产品版本   
  57. strSubBlock.Format("\\StringFileInfo\\%s\\ProductVersion",strTranslation);   
  58. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  59. strSubBlock.ReleaseBuffer();   
  60. strTemp.Format("产品版本:   %s ",pVerValue);   
  61. AfxMessageBox(strTemp);   
  62.   
  63. //版权  
  64. strSubBlock.Format("\\StringFileInfo\\%s\\LegalCopyright",strTranslation);   
  65. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  66. strSubBlock.ReleaseBuffer();   
  67. strTemp.Format("版权:   %s ",pVerValue);   
  68. AfxMessageBox(strTemp);   
  69.   
  70. //公司名  
  71. strSubBlock.Format("\\StringFileInfo\\%s\\CompanyName",strTranslation);   
  72. VerQueryValue(pBlock,strSubBlock.GetBufferSetLength(256),(LPVOID*)&pVerValue,&nSize);   
  73. strSubBlock.ReleaseBuffer();   
  74. strTemp.Format("公司名:   %s ",pVerValue);   
  75. AfxMessageBox(strTemp);   
  76.   
  77.    free(pBlock);  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值