Recent

Author Topic: How to read version of the my application?  (Read 12001 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 793
    • Blog personal
How to read version of the my application?
« on: October 15, 2010, 04:20:45 pm »
Hello, How can I read the version of my application, when it's start.

I would like the version info stored in the exe.

Thanks

/BlueIcaro

faber

  • Guest
Re: How to read version of the my application?
« Reply #1 on: October 15, 2010, 04:35:24 pm »
On windows

Code: [Select]
LectureVersion(paramstr(0))
Code: [Select]
function LectureVersion (chemin : String) : String;
var
   VersionL,Taille    : DWord;
   VersionPC,Buffer   : PChar;
begin
 Result := '';
 Taille := GetFileVersionInfoSize(PChar(chemin), Taille);
 if Taille > 0 then
 try
    Buffer := AllocMem(Taille);
    GetFileVersionInfo(PChar(chemin),0,Taille,Buffer);
    if VerQueryValue(Buffer,PChar('\StringFileInfo\041504B0\FileVersion'),Pointer(VersionPC),VersionL) then
       Result := VersionPC;
 finally
    FreeMem(Buffer,Taille);
 end;
end;

BlueIcaro

  • Hero Member
  • *****
  • Posts: 793
    • Blog personal
Re: How to read version of the my application?
« Reply #2 on: October 15, 2010, 04:52:19 pm »
Thanks for the function
But it's returns empty string. I debug it and does run :   Result := VersionPC;

I add version in the option proyect

I running in Windows 7 Ultimate, may this can be the problem, I don't know

/BlueIcaro

faber

  • Guest
Re: How to read version of the my application?
« Reply #3 on: October 15, 2010, 05:09:34 pm »
Ups, I forget, you should find your lang code. Fastest way:
open your exe with notepad and look for StringFileInfo, then you will see your (this is my \StringFileInfo\041504B0\FileVersion).

mas steindorff

  • Hero Member
  • *****
  • Posts: 533
Re: How to read version of the my application?
« Reply #4 on: October 15, 2010, 05:43:19 pm »
Ups, I forget, you should find your lang code. Fastest way:
open your exe with notepad and look for StringFileInfo, then you will see your (this is my \StringFileInfo\041504B0\FileVersion).

??? I'm lost but here is another way
Code: [Select]
implementation
uses  windows;

function TFrmMain.MyGetVersion(filename:string=''): String;
var
  my :record
    Dummy: DWord;
    VerInfo: Pointer;
    VerInfoSize: DWord;
    VerValueSize: DWord;
    VerValue:  PVSFixedFileInfo;
    end;
begin
  Result:='';
  my.Dummy:=0; // to keep the compiler happy
  if filename='' then filename:=ParamStr(0);
  my.VerInfoSize := GetFileVersionInfoSize(PChar(filename), my.Dummy);
  if my.VerInfoSize=0 then
     exit;
  GetMem(my.VerInfo, my.VerInfoSize);
  GetFileVersionInfo(PChar(filename), 0, my.VerInfoSize, my.VerInfo);
  VerQueryValue(my.VerInfo, '\', Pointer(my.VerValue), my.VerValueSize);
  with my.VerValue^ do  begin
     result := IntTostr(dwFileVersionMS shr 16);
     result := result+'.'+   IntTostr(dwFileVersionMS and $FFFF);
     result := result+'.'+   IntTostr(dwFileVersionLS shr 16);
     result := result+'.'+   IntTostr(dwFileVersionLS and $FFFF);
  end;
  FreeMem(my.VerInfo, my.VerInfoSize);
end;
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

faber

  • Guest
Re: How to read version of the my application?
« Reply #5 on: October 15, 2010, 06:10:54 pm »
??? I'm lost but here is another way
Code: [Select]
...
     result := IntTostr(dwFileVersionMS shr 16);
     result := result+'.'+   IntTostr(dwFileVersionMS and $FFFF);
     result := result+'.'+   IntTostr(dwFileVersionLS shr 16);
     result := result+'.'+   IntTostr(dwFileVersionLS and $FFFF);
...

yes, this is the same, you can use "dwFileVersionMS shr 16 ..." or you can call directly "\StringFileInfo\041504B0\FileVersion" but in that case you must know your lang codepage of your exe descript (in my case 041504B0).

alessandro1500

  • Newbie
  • Posts: 3
Re: How to read version of the my application?
« Reply #6 on: June 21, 2018, 06:33:32 pm »
Anyone know how could I do the same in Linux? "PVSFixedFileInfo" is in windows.pas and I could use a compile directive to port on linux

minesadorada

  • Sr. Member
  • ****
  • Posts: 452
  • Retired
Re: How to read version of the my application?
« Reply #7 on: June 21, 2018, 07:44:22 pm »
Take a look at Lazarus unit FileInfo.  I assume it is crossplatform.
GPL Apps: Health MonitorRetro Ski Run
OnlinePackageManager Components: LazAutoUpdate, LongTimer, PoweredBy, ScrollText, PlaySound, CryptINI

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: How to read version of the my application?
« Reply #8 on: June 21, 2018, 07:51:00 pm »
It is cross-platform for fpc/lazarus applications, but afaik it can not be read by other applications very easily on anything other than Windows.
The application itself can present the data on all platforms.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018