• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

File Version Information

Is there a simple way to get internal file information from EXE's & DLL's?
FileVersion, ProductVersion, etc.
0
Llysander
Asked:
Llysander
  • 3
1 Solution
 
intheCommented:
try this example that puts all the various version info onto labels:

unit GetVerInfoU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, FileCtrl, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    TabControl1: TTabControl;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    FilterComboBox1: TFilterComboBox;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Bevel1: TBevel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    procedure FileListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FileListBox1Click(Sender: TObject);
var
  VerInfoSize: DWORD;         // holds the size of the version info resource
  GetInfoSizeJunk: DWORD;     // a junk variable, its value is ignored
  VersionInfo: Pointer;       // points to the version info resource
  Translation: Pointer;       // holds version info translation table
  InfoPointer: Pointer;       // a pointer to version information
  VersionInfoSize: UINT;      // holds the size of version information
  VersionValue: string;       // holds the version info request string
begin
  {retrieve the size of the version information resource, if one exists}
  VerInfoSize := 0;
  VerInfoSize := GetFileVersionInfoSize(PChar(FileListBox1.FileName),
                                        GetInfoSizeJunk);

  {if there was a version information resource available...}
  if VerInfoSize>0 then
  begin
    {hide the 'not available' indicator}
    Label1.Visible := FALSE;

    {retrieve enough memory to hold the version resource}
    GetMem(VersionInfo, VerInfoSize);

    {retrieve the version resource for the selected file}
    GetFileVersionInfo(PChar(FileListBox1.FileName), 0, VerInfoSize, VersionInfo);

    {retrieve a pointer to the translation table}
    VerQueryValue(VersionInfo, '\\VarFileInfo\\Translation', Translation, VersionInfoSize);

    {initialize the version value request string}
    VersionValue :='\\StringFileInfo\\'+
                  IntToHex(LoWord(LongInt(Translation^)),4)+
                  IntToHex(HiWord(LongInt(Translation^)),4)+
                  '\\';

    {retrieve and display the company name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'CompanyName'), InfoPointer,
                  VersionInfoSize);
    Label17.Caption := string(PChar(InfoPointer));

    {retrieve and display the file description}
    VerQueryValue(VersionInfo, PChar(VersionValue+'FileDescription'), InfoPointer,
                  VersionInfoSize);
    Label16.Caption := string(PChar(InfoPointer));

    {retrieve and display the file version}
    VerQueryValue(VersionInfo, PChar(VersionValue+'FileVersion'), InfoPointer,
                  VersionInfoSize);
    Label15.Caption := string(PChar(InfoPointer));

    {retrieve and display the internal file name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'InternalName'), InfoPointer,
                  VersionInfoSize);
    Label14.Caption := string(PChar(InfoPointer));

    {retrieve and display the legal copyright}
    VerQueryValue(VersionInfo, PChar(VersionValue+'LegalCopyright'), InfoPointer,
                  VersionInfoSize);
    Label13.Caption := string(PChar(InfoPointer));

    {retrieve and display the legal trademarks}
    if VerQueryValue(VersionInfo, PChar(VersionValue+'LegalTrademarks'), InfoPointer,
                     VersionInfoSize) then
      Label19.Caption := string(PChar(InfoPointer))
    else
      Label19.Caption := '';

    {retrieve and display the original file name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'OriginalFilename'), InfoPointer,
                  VersionInfoSize);
    Label12.Caption := string(PChar(InfoPointer));

    {retrieve and display the product name}
    VerQueryValue(VersionInfo, PChar(VersionValue+'ProductName'), InfoPointer,
                  VersionInfoSize);
    Label11.Caption := string(PChar(InfoPointer));

    {retrieve and display the product version}
    VerQueryValue(VersionInfo, PChar(VersionValue+'ProductVersion'), InfoPointer,
                  VersionInfoSize);
    Label10.Caption := string(PChar(InfoPointer));

    {retrieve and display the comments. some version info resources may
     not have this information.}
    if VerQueryValue(VersionInfo, PChar(VersionValue+'Comments'), InfoPointer,
                     VersionInfoSize) then
      Label21.Caption := string(PChar(InfoPointer))
    else
      Label21.Caption := '';

    {retrieve and display file build flags}
    if VerQueryValue(VersionInfo, '\', InfoPointer, VersionInfoSize) then
    begin
      CheckBox1.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_DEBUG);
      CheckBox2.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_PRERELEASE);
      CheckBox3.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_PATCHED);
      CheckBox4.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_PRIVATEBUILD);
      CheckBox5.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_INFOINFERRED);
      CheckBox6.Checked := BOOL(TVSFixedFileInfo(InfoPointer^).dwFileFlags and
                           VS_FF_SPECIALBUILD);
    end
    else
    begin
      CheckBox1.Checked := FALSE;
      CheckBox2.Checked := FALSE;
      CheckBox3.Checked := FALSE;
      CheckBox4.Checked := FALSE;
      CheckBox5.Checked := FALSE;
      CheckBox6.Checked := FALSE;
    end;

    {free the version resource memory}
    FreeMem(VersionInfo, VerInfoSize);
  end
  else
  begin
    {otherwise, indicate that no version information is available}
    Label1.Visible := TRUE;

    {delete any previous version information}
    Label17.Caption := '';
    Label16.Caption := '';
    Label15.Caption := '';
    Label14.Caption := '';
    Label13.Caption := '';
    Label12.Caption := '';
    Label11.Caption := '';
    Label10.Caption := '';
    Label19.Caption := '';
    Label21.Caption := '';

    CheckBox1.Checked := FALSE;
    CheckBox2.Checked := FALSE;
    CheckBox3.Checked := FALSE;
    CheckBox4.Checked := FALSE;
    CheckBox5.Checked := FALSE;
    CheckBox6.Checked := FALSE;
  end;
end;

end.



Regards Barry
0
 
rwilson032697Commented:
I can mail you the source to a version label component which wraps all this stuff up quite nicely...

Cheers,

Raymond.
0
 
LlysanderAuthor Commented:
This piece of code DOES work but in my eternal lazyness I was looking for something a little simpler.  What I was really looking for was a component that I could feed a path and filename to and run an .Execute and it would return as properties all the internal version information as well as size, date/time, etc.  Something comprehensive.
0
 
intheCommented:
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now