delphi获取Exe文件版本信息的函数

Type

TFileVersionInfo = Record

FixedInfo:TVSFixedFileInfo; {版本信息} 
CompanyName:String; {公司名称} 
FileDescription:String; {说明} 
FileVersion:String; {文件版本} 
InternalName:String; {内部名称} 
LegalCopyright:String; {版权} 
LegalTrademarks:String; {合法商标} 
OriginalFilename:String; {源文件名} 
ProductName:String; {产品名称} 
ProductVersion:String; {产品版本} 
Comments:String; {备注} 
LocalPort:String; {Local UDP_Message Port} 
end; 

Function GetFileVerInfo(ExeFileName :Pchar;var VerSionInfo:TFileVersionInfo):Boolean;
var 
dwHandle, dwVersionSize : DWORD; 
Find : String; 
pcBuffer : PChar; 
pTemp : Pointer; 
FileVersionInfo : TVSFixedFileInfo; 
begin 
Find := '\'; 
dwVersionSize := GetFileVersionInfoSize( PChar(ExeFilename),dwHandle ); 
if dwVersionSize = 0 then begin 
Result:=False; 
Exit; 
end; 
GetMem( pcBuffer, dwVersionSize ); 
if not GetFileVersionInfo( PChar(ExeFilename),dwHandle,dwVersionSize,pcBuffer ) then begin 
FreeMem(pcBuffer); 
Result:=False; 
Exit; 
end; 
if not VerQueryValue( pcBuffer,PChar(Find),pTemp,dwVersionSize ) then begin 
FreeMem(pcBuffer); 
Result:=False; 
Exit; 
end; 
FileVersionInfo:=PVSFixedFileInfo(pTemp)^; 
With FileVersionInfo do begin 
VersionInfo.FixedInfo.dwSignature:=dwSignature; 
VersionInfo.FixedInfo.dwStrucVersion:=dwStrucVersion; 
VersionInfo.FixedInfo.dwFileVersionMS:=dwFileVersionMS; 
VersionInfo.FixedInfo.dwFileVersionLS:=dwFileVersionLS; 
VersionInfo.FixedInfo.dwProductVersionMS:=dwProductVersionMS; 
VersionInfo.FixedInfo.dwProductVersionLS:=dwProductVersionLS; 
VersionInfo.FixedInfo.dwFileFlagsMask:=FileVersionInfo.dwFileFlagsMask; 
VersionInfo.FixedInfo.dwFileFlags:=fileVersionInfo.dwFileFlags; 
VersionInfo.FixedInfo.dwFileOS:=FileVersionInfo.dwFileOS; 
VersionInfo.FixedInfo.dwFileType:=FileVersionInfo.dwFileType; 
VersionInfo.FixedInfo.dwFileSubtype:=FileVersionInfo.dwFileSubtype; 
VersionInfo.FixedInfo.dwFileDateMS:=FileVersionInfo.dwFileDateMS; 
VersionInfo.FixedInfo.dwFileDateLS:=FileVersionInfo.dwFileDateLS; 
end; 
Find := '\StringFileInfo\080403A8\'; 
if VerQueryValue( pcBuffer,PChar(Find+'CompanyName'),pTemp,dwVersionSize ) then 
VersionInfo.CompanyName:=PChar(pTemp) 
else begin 
Find := '\StringFileInfo\040904E4\'; 
if VerQueryValue( pcBuffer,PChar(Find+'CompanyName'),pTemp,dwVersionSize ) then 
VersionInfo.CompanyName:=PChar(pTemp) 
else begin 
Result:=False; 
Exit; 
end; 
end; 
if VerQueryValue( pcBuffer,PChar(Find+'FileDescription'),pTemp,dwVersionSize ) then 
VersionInfo.FileDescription:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'FileVersion'),pTemp,dwVersionSize ) then 
VersionInfo.FileVersion:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'InternalName'),pTemp,dwVersionSize ) then 
VersionInfo.InternalName:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'LegalCopyright'),pTemp,dwVersionSize ) then 
VersionInfo.LegalCopyright:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'LegalTrademarks'),pTemp,dwVersionSize ) then 
VersionInfo.LegalTrademarks:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'OriginalFilename'),pTemp,dwVersionSize ) then 
VersionInfo.OriginalFilename:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'ProductName'),pTemp,dwVersionSize ) then 
VersionInfo.ProductName:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'ProductVersion'),pTemp,dwVersionSize ) then 
VersionInfo.ProductVersion:=PChar(pTemp); 

if VerQueryValue( pcBuffer,PChar(Find+'Comments'),pTemp,dwVersionSize ) then 
VersionInfo.Comments:=PChar(pTemp); 
if VerQueryValue( pcBuffer,PChar(Find+'LocalPort'),pTemp,dwVersionSize ) then 
VersionInfo.LocalPort:=PChar(pTemp) 
else 
VersionInfo.LocalPort:='66500'; 
FreeMem(pcBuffer ); 
Result:=True; 
end;

Delphi获取其他exe程序版本号的更多相关文章

  1. Delphi获取指定文件的版本号

    获取指定文件的版本号 方式一: function GetFileVersion(FileName: string): string; type PVerInfo = ^TVS_FIXEDFILEINF ...

  2. Delphi 中将一些 Dll等生成资源文件打包成一个独立的EXE程序方法步骤

    资源文件一般为扩展名为res的文件,其自带的资源编译工具BRCC32.EXE(位于/Delphi/BIN目录下) 1.编写rc脚本文本 用记事本或其它文本编辑器编写一个扩展名为rc的文件,格式分别为在 ...

  3. Python 获得程序 exe 的版本号

    Python 获得程序 exe 的版本号 python中需要安装 pywin32 包 # based on http://stackoverflow.com/questions/580924/pyth ...

  4. Delphi获取文件名、文件名不带扩展名、文件名的方法;delphi 获取文件所在路径

    取文件名 ExtractFileName(FileName); 取文件扩展名: ExtractFileExt(filename); 取文件名,不带扩展名: 方法一:   Function Extrac ...

  5. java实现可安装的exe程序

    java实现可安装的exe程序 通过编写Java代码,实现可安装的exe文件的一般思路: 1.在eclipse中创建java项目,然后编写Java代码,将编写好的Java项目导出一个.jar格式的ja ...

  6. C#、ASP.NET获取当前应用程序的绝对路径,获取程序工作路径 (转帖)

    C#.ASP.NET获取当前应用程序的绝对路径,获取程序工作路径   ============================================ 使用 Application.Start ...

  7. Qt界面中嵌入其他exe程序的界面,使用Qt5

    下面用一个小例子来演示如何在Qt的界面中嵌入其他exe程序的界面,最终效果如下图所示.本文参考了 http://blog.csdn.net/jiaoyaziyang/article/details/4 ...

  8. WPF 程序中启动和关闭外部.exe程序

    当需要在WPF程序启动时,启动另一外部程序(.exe程序)时,可以按照下面的例子来: C#后台代码如下: using System; using System.Collections.Generic; ...

  9. [转]Delphi中,让程序只运行一次的方法

    program onlyRunOne; uses Forms,Windows,SysUtils, Dialogs, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} v ...

随机推荐

  1. 02基于python玩转人工智能最火框架之TensorFlow人工智能&深度学习介绍

    人工智能之父麦卡锡给出的定义 构建智能机器,特别是智能计算机程序的科学和工程. 人工智能是一种让计算机程序能够"智能地"思考的方式 思考的模式类似于人类. 什么是智能? 智能的英语 ...

  2. leetcode第一刷_Insert Interval

    这道题的难度跟微软的那道面试题相当. 要在集合中插入一段新的集合,相当于求两个集合的并了.对于新增加一段集合的情况,分为以下几种: 1. 增加段跟原来的全然相交,也即他的起点和终点都在被包括在原来的段 ...

  3. HDU1370(中国剩余定理)

    昨天我细致一想,发现自己之前的分类(用OJ来划分,毫无意义啊.)太失败了,所以我又一次划分了一下大分类,在分到数论的时候,我就想起了中国剩余定理了.于是乎今天就刷了一题中国剩余定理的题目了.话说太久没 ...

  4. DevExpress 中 设置 labelControl 的背景透明到图片的方法

    labelControl 中的 backColor 可以设置为: TransParent 当设置为: Transparent 的时候,labelControl 的背景依然为 主form的背景颜色 ,研 ...

  5. 学习笔记:Javascript 变量 包装对象

    学习笔记:Javascript 变量 包装对象 如下代码,可以输出字符的长度. var str = "Tony"; str.length; 这时再试试以下代码,返回是 undefi ...

  6. 基于 debian:stretch-slim 系统镜像的 docker 镜像,安装 curl

    依次运行如下命令: apt-get update apt-get install curl

  7. git merge 和 git merge --no-ff

    根据这张图片可以看出 git merge –no-ff 可以保存你之前的分支历史.能够更好的查看 merge历史,以及branch 状态. git merge 则不会显示 feature,只保留单条分 ...

  8. HTTP 状态码的完整列表

    一.1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态码.SC_CONTINUE = 100; 100(继续)请求者应当继续提出请求.服务器返回此代码表示已收到请求的第一部分,正在等待其余 ...

  9. HanLP中的人名识别分析详解

    在看源码之前,先看几遍论文<基于角色标注的中国人名自动识别研究> 关于命名识别的一些问题,可参考下列一些issue: u u名字识别的问题 #387 u u机构名识别错误 u u关于层叠H ...

  10. mysql 备份与还原恢复

    一.数据备份 1.使用mysqldump命令备份 mysqldump命令将数据库中的数据备份成一个文本文件.表的结构和表中的数据将存储在生成的文本文件中. mysqldump命令的工作原理很简单.它先 ...