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


本文整理自网络,侵删。

 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消息发送字符串

Delphi编程防止界面卡死的方法

Delphi 调用相应程序打开网址

Delphi 修改快捷方式

Delphi ioutils 单元(5): tdirectory.tdirectory 的其他功能

apk权限大全 android必懂知识

Delphi中stringgrid删除行

Delphi实现票据精确打印

Delphi 线程教学第一节:初识多线程

Delphi 内存管理[2-3]

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...