// '%d.%d.%d.%d' => '4.13.128.0'
// '%.2d-%.2d-%.2d' => '04-13-128'
function GetFileVersion(const FileName: String;
const Fmt: String = '%d.%d.%d.%d'): String;
var
iBufferSize: DWORD;
iDummy: DWORD;
pBuffer: Pointer;
pFileInfo: Pointer;
iVer: Array[1..4] of Word;
begin
// set default value
Result := '';
// get size of version info (0 if no version info exists)
iBufferSize := GetFileVersionInfoSize(PChar(FileName), iDummy);
if (iBufferSize > 0) then
begin
GetMem(pBuffer, iBufferSize);
try
// get fixed file info
GetFileVersionInfo(PChar(FileName), 0, iBufferSize, pBuffer);
VerQueryValue(pBuffer, '\', pFileInfo, iDummy);
// read version blocks
iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
finally
FreeMem(pBuffer);
end;
// format result string
Result := Format(Fmt, [iVer[1], iVer[2], iVer[3], iVer[4]]);
end;
end;