Type Tfileversioninfo = Record
Fixedinfo:tvsfixedfileinfo; {Version Information}
companyname:string; {Company Name}
filedescription:string; Description
fileversion:string; {file Version}
internalname:string; {Internal name}
legalcopyright:string; Copyright
legaltrademarks:string; {Legal Trademark}
originalfilename:string; {Source file name}
productname:string; {Product Name}
productversion:string; {Product Version}
comments:string; Notes
localport:string; {Local Udp_message Port}
End
Function getfileverinfo (exefilename:P char;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
function to get version information of EXE file (use GetFileVersionInfo to get Tfileversioninfo struct, contains 12 items)