GetFileVersion

How to get the file version of a file as a string.

function GetFileVersion(const Filename: string; var Version: string): Boolean;

var

  VerBlk: VS_FIXEDFILEINFO;

  InfoSize,puLen : DWord;

  Pt,InfoPtr : Pointer;

begin

  Version := '';

  InfoSize := GetFileVersionInfoSize(PChar(Filename), puLen);

  FillChar(VerBlk, SizeOf(VS_FIXEDFILEINFO),0);

  if InfoSize > 0 then

  begin

    GetMem(Pt, InfoSize);

    GetFileVersionInfo(PChar(Filename), 0, InfoSize, Pt);

    VerQueryValue(Pt, '\', InfoPtr, puLen);

    move(InfoPtr^, VerBlk, SizeOf(VS_FIXEDFILEINFO));

    Version := Format('%d.%d.%d.%d',[VerBlk.dwFileVersionMS shr 16,

      VerBlk.dwFileVersionMS and 65535,



      VerBlk.dwFileVersionLS shr 16,

      VerBlk.dwFileVersionLS and 65535]);

    FreeMem(Pt);

    Result := True;

  end else

    Result := False;

end;

 

Share this article!

Follow us!

Find more helpful articles: