Board index » delphi » Getting version info from a .EXE

Getting version info from a .EXE

I want a program to get the version info about itself or any other program.
At worst I could display the Properties form if I could work out which API
to call but I would rather get the raw information so that I could process
it how I want.

I have searched help etc. but can't seem to find what I want.

Alec Ford

 

Re:Getting version info from a .EXE


I do it this way:

procedure TForm1.Button1Click(Sender: TObject);
var
  P: Pointer;
  R: PChar;
  S, Zero: Integer;
begin
  ListBox1.Items.Clear;
  S := GetFileVersionInfoSize(PChar(Application.ExeName), Zero);
  if S > 0 then
  begin
    GetMem(P, S);
    GetFileVersionInfo(PChar(Application.ExeName), 0, S, P);
    //
    R := StrAlloc(1024);
    if VerQueryValue(P, '\\StringFileInfo\\040904E4\\ProductName', R, 1024)
then
      ListBox1.Add('ProductName: ' + StrPas(R));
    if VerQueryValue(P, '\\StringFileInfo\\040904E4\\LegalCopyright', R,
1024) then
      ListBox1.Add('LegalCopyright: ' + StrPas(R));
    <...>
    //
    StrDispose(R);
    FreeMem(P, S);
  end;
end;

The predefined version information strings are:

CompanyName
FileDescription
FileVersion
InternalName
LegalCopyright
OriginalFilename
ProductName
ProductVersion

.sau
alienvis...@mail.ru

Quote
Alec Ford <alecf...@clear.net.nz> wrote in message

news:3ad62162$1@clear.net.nz...
Quote
> I want a program to get the version info about itself or any other
program.
> At worst I could display the Properties form if I could work out which API
> to call but I would rather get the raw information so that I could process
> it how I want.

> I have searched help etc. but can't seem to find what I want.

> Alec Ford

Re:Getting version info from a .EXE


Thank you for that, I got hung up on GetVersion and couldn't work out what
to search for but now that I know I have plenty of information.  Anyone
following this thread might like to know that TI 2713 covers this topic.  I
hadn't looked at the TI list for ages, I must next time I have a similar
problem.

Alec Ford

Re:Getting version info from a .EXE


It finally took me ages to get it working, because my default language is
not American English!!

Anyone follow the thread might like to know that if you are not using the
default of American English the code of 040904E4 needs to be changed

A few lines in the right places like:

var
 Transtable        : PLongint;
  SBSize: UInt;
....
   VerQueryValue(P,'\VarFileInfo\Translation',  pointer(Transtable),
SBSize);
   LangCode :=  Format('%.4x%.4x',
 LoWord(Transtable^),HiWord(Transtable^)]);
....
    if VerQueryValue(P, '\\StringFileInfo\\'+LangCode'+\\ProductName', R,
1024)
....

And now it will work for any exe etc whatever language it was compile with.

Alec Ford

Quote
Donov Aleksey wrote in message <9b6ofr$1i4...@sa.aaanet.ru>...
>I do it this way:

>procedure TForm1.Button1Click(Sender: TObject);
>var
>  P: Pointer;
>  R: PChar;
>  S, Zero: Integer;
>begin
>  ListBox1.Items.Clear;
>  S := GetFileVersionInfoSize(PChar(Application.ExeName), Zero);
>  if S > 0 then
>  begin
>    GetMem(P, S);
>    GetFileVersionInfo(PChar(Application.ExeName), 0, S, P);
>    //
>    R := StrAlloc(1024);
>    if VerQueryValue(P, '\\StringFileInfo\\040904E4\\ProductName', R, 1024)
>then
>      ListBox1.Add('ProductName: ' + StrPas(R));
>    if VerQueryValue(P, '\\StringFileInfo\\040904E4\\LegalCopyright', R,
>1024) then
>      ListBox1.Add('LegalCopyright: ' + StrPas(R));
>    <...>
>    //
>    StrDispose(R);
>    FreeMem(P, S);
>  end;
>end;

>The predefined version information strings are:

>CompanyName
>FileDescription
>FileVersion
>InternalName
>LegalCopyright
>OriginalFilename
>ProductName
>ProductVersion

>.sau
>alienvis...@mail.ru

>Alec Ford <alecf...@clear.net.nz> wrote in message
>news:3ad62162$1@clear.net.nz...
>> I want a program to get the version info about itself or any other
>program.
>> At worst I could display the Properties form if I could work out which
API
>> to call but I would rather get the raw information so that I could
process
>> it how I want.

>> I have searched help etc. but can't seem to find what I want.

>> Alec Ford

Other Threads