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. Linux 定时任务crontab使用

    正好要搞一个定时删除数据的功能,想到linux 可设置定时器定时执行任务就学习了下~ 并不是所有的linux服务器上都装了crontab 像我这: [root@hehe local]# crontab ...

  2. k8s-YAML配置文件

    一.YAML基础 YAML是专门用来写配置文件的语言,非常简洁和强大,使用比json更方便.它实质上是一种通用的数据串行化格式. YAML语法规则: 大小写敏感 使用缩进表示层级关系 缩进时不允许使用 ...

  3. 推荐一个 .Net Core 的 Redis 库

    这是一个网友写的,原文如下: https://www.cnblogs.com/kellynic/p/9803314.html

  4. TypeScript 之 泛型

    https://m.runoob.com/manual/gitbook/TypeScript/_book/doc/handbook/Generics.html 泛型:可以支持多种类型的数据 泛型函数的 ...

  5. Eclipse配置问题

    1.eclipse中通过search打开第二个文件时第一个文件自动关闭问题: 解决方案: window-preferences-general-search找到第一行的一个选项  reuse edit ...

  6. HanLP分词命名实体提取详解

    HanLP分词命名实体提取详解   分享一篇大神的关于hanlp分词命名实体提取的经验文章,文章中分享的内容略有一段时间(使用的hanlp版本比较老),最新一版的hanlp已经出来了,也可以去看看新版 ...

  7. mysql主从复制常见故障解决

    一.主从复制常见故障 1.从库已存在数据库,主库建立同名库导致从库同步失败.报错如下: mysql> show slave status\G*************************** ...

  8. Linux命令之sed

    sed命令格式 sed [options] 'command' file(s) 选项 -e :直接在命令行模式上进行sed动作编辑,此为默认选项; -f :将sed的动作写在一个文件内,用–f fil ...

  9. NPC问题及证明

    致谢:http://www.docin.com/p-1902790324.html

  10. 53题看透java线程

    1) 什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成 ...