Get VersionInfo strings of youe executable  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 16/05/01

Tip accessed 1293 times

 


We now have a tip:

[76] - Get the version of your application as defined in the Delphi's IDE

that it allowed us to obtain the information that Delphi adds to the executable with its data, such as version, revision, etc.
As you will know, all this data can be defined in the Delphi's IDEi, in:


 Project -> Options -> VersionInfo



This trick is an extensión of this, that will allow us to obtain the rest of data that it can be defined: Description of the file, internal Name, Company, etc...

The biggest complication is the one of knowing how to obtain the information by means of the API function: VerQueryValue, since is to make it in two phases:

First, we should obtain a hexadecimal number that corresponds to the ' languaje-character definition' that, it is dependent of the language in that have compiled the application.
Once we have this fact, we will be able to request the rest of the information.

In the following example, we request the description of the application:


 procedure TForm1.Button1Click(Sender: TObject);

  function  GetAppInfo(De:string):string;

  {Se pueden pedir los siguientes datos:
     CompanyName
     FileDescription
     FileVersion
     InternalName
     LegalCopyright
     OriginalFilename
     ProductName
     ProductVersion
  }

  type
    PaLeerBuffer = array [0..MAX_PATH] of char;

  var
   Size, Size2 : DWord;
   Pt, Pt2     : Pointer;
   Idioma      : string;

   begin
     Result:='';
     Size := GetFileVersionInfoSize(PChar (Application.Exename), Size2);
     if Size > 0 then
     begin
       GetMem (Pt, Size);
       GetFileVersionInfo (PChar (ParamStr (0)), 0, Size, Pt);
       {Obtenemos la cadena de translacion, requerida para obtener el resto
       de datos del Versioninfo}
       VerQueryValue( Pt, '\VarFileInfo\Translation',Pt2, Size2);
       Idioma:=IntToHex( DWord(Pt2^) ,8 );
       {Le damos la vuelta (Es windows, que quieres...}
       Idioma:=Copy(Idioma,5,4)+Copy(Idioma,1,4);

       {Pedimos la info requerida...}
       VerQueryValue( Pt,
                      Pchar('\StringFileInfo\'+
                      Idioma+'\'+
                      De),
                      Pt2, Size2);
       if Size2 > 0 then
       begin
         {Y la devolvemos}
         Result:=Copy(PaLeerBuffer(Pt2^),1,Size2);
       end else
         raise Exception.Create( 'No existe esa informacion en este ejecutable'+
                                 #13+
                                 'There are not this info in this executable');
       FreeMem (Pt);
     end else
       raise exception.Create ( 'Lo siento, no hay VersionInfo disponible '+
                                'en este ejecutable.'+#13+
                                'Sorry there are not VersionInfo available'+
                                'in this executable.');
   end;

 begin
   Form1.Caption:=Form1.Caption+' '+ GetAppInfo('FileDescription');
 end;




Sent by: Régent Beaulieu (rbeaulieu@voximage.com)
I suggest to you to modify your function (386) to let us pass the fName parameter as the exec file name. (Is more usefull for checking versions between two files).
Here you have:


 function  GetAppInfo(De:string; fName: string):string;

  {Se pueden pedir los siguientes datos:
     CompanyName
     FileDescription
     FileVersion
     InternalName
     LegalCopyright
     OriginalFilename
     ProductName
     ProductVersion
  }

  type
    PaLeerBuffer = array [0..MAX_PATH] of char;

  var
   Size, Size2 : DWord;
   Pt, Pt2     : Pointer;
   Idioma      : string;

   begin
     Result:='';
     Size := GetFileVersionInfoSize(PChar (fName), Size2); {First modification !}
     if Size > 0 then
     begin
       GetMem (Pt, Size);
       GetFileVersionInfo (PChar (fName), 0, Size, Pt); {Last modification !}
       {Obtenemos la cadena de translacion, requerida para obtener el resto
       de datos del Versioninfo}
       VerQueryValue( Pt, '\VarFileInfo\Translation',Pt2, Size2);
       Idioma:=IntToHex( DWord(Pt2^) ,8 );
       {Le damos la vuelta (Es windows, que quieres...}
       Idioma:=Copy(Idioma,5,4)+Copy(Idioma,1,4);

       {Pedimos la info requerida...}
       VerQueryValue( Pt,
                      Pchar('\StringFileInfo\'+
                      Idioma+'\'+
                      De),
                      Pt2, Size2);
       if Size2 > 0 then
       begin
         {Y la devolvemos}
         Result:=Copy(PaLeerBuffer(Pt2^),1,Size2);
       end else
         raise Exception.Create( 'No existe esa informacion en este ejecutable'+
                                 #13+
                                 'There are not this info in this executable');
       FreeMem (Pt);
     end else
       raise exception.Create ( 'Lo siento, no hay VersionInfo disponible '+
                                'en este ejecutable.'+#13+
                                'Sorry there are not VersionInfo available'+
                                'in this executable.');
   end;

 


Updated at 16/05/2001 (FileName as parameter)