Posted By

icebob on 08/02/10


Tagged


Versions (?)

Get execute file version as formatted string


 / Published in: Delphi
 

  1. function GetFileVersion(filename: string = ''; const Fmt: string = '%d.%d.%d.%d'): string;
  2. var
  3. iBufferSize: DWORD;
  4. iDummy: DWORD;
  5. pBuffer: Pointer;
  6. pFileInfo: Pointer;
  7. iVer: array[1..4] of word;
  8. begin
  9. // set default value
  10. if filename = '' then
  11. FileName := Application.ExeName;
  12. Result := '';
  13. // get size of version info (0 if no version info exists)
  14. iBufferSize := GetFileVersionInfoSize(PChar(filename), iDummy);
  15. if (iBufferSize > 0) then
  16. begin
  17. Getmem(pBuffer, iBufferSize);
  18. try
  19. // get fixed file info
  20. GetFileVersionInfo(PChar(filename), 0, iBufferSize, pBuffer);
  21. VerQueryValue(pBuffer, '\', pFileInfo, iDummy);
  22. // read version blocks
  23. iVer[1] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
  24. iVer[2] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionMS);
  25. iVer[3] := HiWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
  26. iVer[4] := LoWord(PVSFixedFileInfo(pFileInfo)^.dwFileVersionLS);
  27. finally
  28. Freemem(pBuffer);
  29. end;
  30. // format result string
  31. Result := Format(Fmt, [iVer[1], iVer[2], iVer[3], iVer[4]]);
  32. end;
  33. end;

Report this snippet  

You need to login to post a comment.