// Variante 1
function GetFileVersion1(FileName: TFilename): string;
var
Null, InfoSize, FixInfo: DWord;
PFixInfo: PVSFixedFileInfo;
Zeiger: Pointer;
begin
result := 'nicht ermittelt';
Null := 0;
InfoSize := GetFileVersionInfoSize(PChar(Filename), Null);
if InfoSize > 0 then begin
Zeiger := GetMemory(InfoSize);
if assigned(Zeiger) then begin
GetFileVersionInfo(PChar(Filename), Null, InfoSize, Zeiger);
if VerQueryValue(Zeiger, '\', Pointer(PFixInfo), FixInfo) then begin
result := Format('%d.%d.%d.%d',
[HiWord(PFixInfo^.dwFileVersionMS),
LoWord(PFixInfo^.dwFileVersionMS),
HiWord(PFixInfo^.dwFileVersionLS),
LoWord(PFixInfo^.dwFileVersionLS)]);
end;
FreeMemory(Zeiger);
end;
end;
end;
// Variante 2
function GetFileVersion2(FileName: TFilename): string;
var Value, zeiger: PChar;
Fixinfo, Infosize: DWord;
begin
Infosize := 0;
result := 'nicht ermittelt';
Infosize := GetFileVersionInfoSize(PChar(FileName), Infosize);
if Infosize > 0 then begin
zeiger := AllocMem(Infosize);
try
if GetFileVersionInfo(PChar(FileName), 0, Infosize, zeiger) then begin
if VerQueryValue(zeiger, PChar('StringFileInfo\040704E4\FileVersion'),
Pointer(Value), Fixinfo) then
result := StrPas(Value);
end;
finally
FreeMem(zeiger, Infosize);
end;
end;
end;
// Beispielaufruf
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage('Version: ' + GetFileVersion1('K:\FileCompare.exe'));
showmessage('Version: ' + GetFileVersion2(Application.exename));
end;