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;
http://blog.csdn.net/henreash/article/details/2246774