PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Looking for dll call to retrieve properties from an EXE  (Read 579 times)

Bob Sosbee

  • Member
  • **
  • Posts: 9
    • View Profile
Looking for dll call to retrieve properties from an EXE
« on: March 05, 2019, 02:54:09 PM »
I seem to remember from one of the old Direxions or possibly a Sage MD event there was a DLL call that we could use to retrieve the properties from a file or EXE.  Does anyone have an example or can point me in the right direction?  I have to check if I need to run an update when a file is downloaded, but only if the EXE product version changed.  See attached example.

EVa

  • Member
  • **
  • Posts: 18
    • View Profile
    • EDIAS
Re: Looking for dll call to retrieve properties from an EXE
« Reply #1 on: March 06, 2019, 04:51:07 AM »
Bob,


Something like this ?

0010 BEGIN
0020 LET exe$="D:\pxplus\pvxplus9\pxplus.exe"+$00$
0030 DIM tmp$(512,$00$)
0040 LET size=DLL("version.dll","GetFileVersionInfoSizeA",exe$,tmp$)
0050 IF size=0 THEN GOTO ERROR ELSE DIM tmp$(0)
0060 DIM bfr$(size,$00$)
0070 LET r=DLL("version.dll","GetFileVersionInfoA",exe$,$$,size,bfr$)
0080 IF r=0 THEN GOTO ERROR
0090 DIM where$(4,$00$),length$(4,$00$)
0100 LET r=DLL("version.dll","VerQueryValueA",bfr$,"\\"+$00$,where$,length$)
0110 IF r=0 THEN GOTO ERROR
0120 ! VS_FIXEDFILEINFO structure
0130 ! dwFileVersionMS = 9,4
0140 ! dwFileVersionLS = 13,4
0150 ! dwProductVersionMS = 17,4
0160 ! dwProductVersionLS = 21,4
0170 LET tmp$=MEM(DEC(SWP(where$)),DEC(SWP(length$)))
0180 LET tmp$=SWP(tmp$(9,4))+SWP(tmp$(13,4))+SWP(tmp$(17,4))+SWP(tmp$(21,4))
0190 LET fv$=""; FOR n=1 TO 8 STEP 2; LET fv$+=STR(DEC(tmp$(n,2)))
0200 IF n<8 THEN LET fv$+="." END_IF ; NEXT ; PRINT "FileVersion: ",fv$
0210 LET pv$=""; FOR n=9 TO 16 STEP 2; LET pv$+=STR(DEC(tmp$(n,2)))
0220 IF n<16 THEN LET pv$+="." END_IF ; NEXT ; PRINT "ProductVersion: ",pv$
0230 STOP
0240 !
0250 ERROR: LET error=DLL("kernel32","GetLastError")
0260 LET size=512,text$=DIM(size,$00$)
0270 LET result=DLL("Kernel32","FormatMessageA",DEC($1000$),0,error,0,text$,size,0)
0280 IF result=0 THEN {
0290 PRINT "An unknown error occured" } ELSE {
0300 PRINT text$(1,POS($0D0A$=text$))
0310  }

-Eric-

harryv

  • Member
  • **
  • Posts: 9
    • View Profile
Re: Looking for dll call to retrieve properties from an EXE
« Reply #2 on: March 06, 2019, 08:08:24 AM »
EVa - I tried this program on pxp2018 and the product version came out wrong.

Just a FYI.
Regards,

Harry Valters

EVa

  • Member
  • **
  • Posts: 18
    • View Profile
    • EDIAS
Re: Looking for dll call to retrieve properties from an EXE
« Reply #3 on: March 06, 2019, 08:50:46 AM »
Harry,


Don't know why that is - it works for non pxplus executables.  Try this one:

0020 LET exe$="C:\Windows\System32\cmd.exe"+$00$


-Eric-

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3197
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Looking for dll call to retrieve properties from an EXE
« Reply #4 on: March 06, 2019, 03:06:35 PM »
Harry

I tried this on a standard install of PxPlus 2018 (update 1) and got:

-:run
FileVersion: 15.10.0.0.
ProductVersion: 15.10.0.0.
-:


I simply changed line 20 to:

0020 LET EXE$=ARG(0)+$00$

and ran the code.

harryv

  • Member
  • **
  • Posts: 9
    • View Profile
Re: Looking for dll call to retrieve properties from an EXE
« Reply #5 on: March 06, 2019, 03:48:21 PM »
Mike,

I did the same and get

FileVersion: 15.0.1.0.
ProductVersion: 15.0.1.0.

The File Version is correct
But in the properties detail the Product Version is 15.00.0001
I'm not sure if the number of zeros makes a difference if not then the numbers are the same.


Regards,

Harry Valters

Jeff Wilder

  • Silver Member
  • ***
  • Posts: 20
    • View Profile
Re: Looking for dll call to retrieve properties from an EXE
« Reply #6 on: March 06, 2019, 05:05:13 PM »
Harry,
I think the differences are because of the way Windows formats the structure data for display.  In Windows, a Product Version is made up of major.minor.build. My understanding is that the Windows Installer ignores the private part. In this case, 15.0.1 or formatted as 15.00.0001.

From Windows Product Version
"Note that Windows Installer uses only the first three fields of the product version. If you include a fourth field in your product version, the installer ignores the fourth field."

From Windows FileVersion (.Net)
Typically, a version number is displayed as "major number.minor number.build number.private part number".
A file version number is a 64-bit number that holds the version number for a file as follows:
The first 16 bits are the FileMajorPart number.
The next 16 bits are the FileMinorPart number.
The third set of 16 bits are the FileBuildPart number.
The last 16 bits are the FilePrivatePart number.

You just need to tweak lines 190-220 to format the numbers as Windows normally would.

Regards,
Jeff

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3197
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Looking for dll call to retrieve properties from an EXE
« Reply #7 on: March 07, 2019, 08:58:09 AM »
Just to bring this discussion back to the original question that Bob posted which was how to determine if the versions are different ...

The formatting of the version information should be immaterial for the purposes of comparison, as long it is consistent the logic should be fine.

One thing I would point out though, there is no MANDATORY hard and fast rule that developers must include or update the version number or build number in an EXE.  For example, we on occasion, provide clients a temporary patched EXE to see if a change we have made works as expected (Alpha testing, etc.).  This often will not involve changing the version or even the build number thus checking the version would not work.  We do change the version/build number when we officially release product. 

(BTW: Not all EXE's include version information and I have seen a few products with the internal version still set to 1.0.0.0 even after many releases)

I would suggest that you check the version and file size.  Also you can check the file modification dates to see if the modification date of the potentially newer EXE is more recent than that of the system being updated.

Bob Sosbee

  • Member
  • **
  • Posts: 9
    • View Profile
Re: Looking for dll call to retrieve properties from an EXE
« Reply #8 on: March 08, 2019, 03:53:15 PM »
That's fine - we're building the EXE, so we control the version upgrades.  I'm also building a part of our EMV suite to check that the client is current last updated, so if a new version is auto downloaded, I check the actual version (not using dates) and know if I need to run it to update the EMV client.

That's what I needed.