Kopiuj
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TFileVersionInfo = record
fCompanyName,
fFileDescription,
fFileVersion,
fInternalName,
fLegalCopyRight,
fLegalTradeMark,
fOriginalFileName,
fProductName,
fProductVersion,
fComments: string;
end;
var
Form1: TForm1;
FileVersionInfo: TFileVersionInfo;
implementation
{$R *.dfm}
procedure GetAppVersionInfo(sAppNamePath: string);
var
VerSize: integer;
VerBuf: PChar;
VerBufValue: pointer;
{$IFDEF Delphi3Below}
VerHandle: integer;
VerBufLen: integer;
{$ELSE}
VerHandle: cardinal;
VerBufLen: cardinal;
{$ENDIF}
VerKey: string;
function GetInfo(ThisKey: string): string;
begin
Result := '';
VerKey := '\StringFileInfo\' + IntToHex(loword(integer(VerBufValue^)), 4) +
IntToHex(hiword(integer(VerBufValue^)), 4) + '\' + ThisKey;
if VerQueryValue(VerBuf, PChar(VerKey), VerBufValue, VerBufLen) then
Result := StrPas(VerBufValue);
end;
function QueryValue(ThisValue: string): string;
begin
Result := '';
if GetFileVersionInfo(PChar(sAppNamePath), VerHandle, VerSize, VerBuf) and
VerQueryValue(VerBuf, '\VarFileInfo\Translation', VerBufValue, VerBufLen) then
Result := GetInfo(ThisValue);
end;
begin
if sAppNamePath = '' then
sAppNamePath := Application.ExeName;
VerSize := GetFileVersionInfoSize(PChar(sAppNamePath), VerHandle);
VerBuf := AllocMem(VerSize);
try
FileVersionInfo.fCompanyName := QueryValue('CompanyName');
FileVersionInfo.fFileDescription := QueryValue('FileDescription');
FileVersionInfo.fFileVersion := QueryValue('FileVersion');
FileVersionInfo.fInternalName := QueryValue('InternalName');
FileVersionInfo.fLegalCopyRight := QueryValue('LegalCopyRight');
FileVersionInfo.fLegalTradeMark := QueryValue('LegalTradeMark');
FileVersionInfo.fOriginalFileName := QueryValue('OriginalFileName');
FileVersionInfo.fProductName := QueryValue('ProductName');
FileVersionInfo.fProductVersion := QueryValue('ProductVersion');
FileVersionInfo.fComments := QueryValue('Comments');
finally
FreeMem(VerBuf, VerSize);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetAppVersionInfo('C:\AQQ.exe');
ShowMessage(FileVersionInfo.fFileDescription) ;
end;
end.
działa dla plików *.exe oraz *.dll