NO

Author Topic: Retrieving the version of an exe\dll  (Read 883 times)

Offline Vortex

  • Member
  • *
  • Posts: 942
    • http://www.vortex.masmcode.com
Retrieving the version of an exe\dll
« on: January 12, 2025, 08:29:23 PM »
Here is a command line tool to get the version of the an exe\dll.

Tested on Windows 7 Sp1 :

Code: [Select]
GetFileVersion.exe C:\Windows\System32\ntdll.dll
6.1.7601.24545
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 954
Re: Retrieving the version of an exe\dll
« Reply #1 on: January 13, 2025, 03:43:31 AM »
Thanks Vortex,

Tested in WIN 11 23H2 - works but gives different answer, previously looking at file details in windows explorer I got 10.0.2261.4541 (attached screen shot) similar but different  ;)

C:\Users\John\Downloads>GetFileVersion.exe C:\Windows\System32\ntdll.dll
6.2.22621.4541

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2189
Re: Retrieving the version of an exe\dll
« Reply #2 on: January 13, 2025, 05:57:39 AM »
Check C:\windows\SysWOW64\ntdll.dll with Explorer, as 32-bit app find it.

C version of GetVersionInfo for testing :
GetVersionInfo()
AddInLoad, Add-In loader
« Last Edit: January 13, 2025, 06:14:42 AM by TimoVJL »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 954
Re: Retrieving the version of an exe\dll
« Reply #3 on: January 13, 2025, 10:04:40 AM »
SysWOW64 result

C:\Users\John\Downloads>GetFileVersion.exe C:\Windows\SysWOW64\\ntdll.dll
6.2.22621.4541
C:\Users\John\Downloads>

Still different 10.0.22621.4541 but similar...

John Z

Offline Vortex

  • Member
  • *
  • Posts: 942
    • http://www.vortex.masmcode.com
Re: Retrieving the version of an exe\dll
« Reply #4 on: January 13, 2025, 11:14:08 AM »
Hello,

On my computer at work ( Windows 11 2024 H2 ) :

Code: [Select]
Microsoft Windows [Version 10.0.26100.2605]

C:\>GetFileVersion.exe C:\Windows\System32\ntdll.dll
6.2.26100.2605
C:\>GetFileVersion.exe C:\Windows\SysWOW64\ntdll.dll
6.2.26100.2605

I guess the first step, retrieving the version of  C:\Windows\System32\ntdll.dll is redirected to C:\Windows\SysWOW64\ntdll.dll
« Last Edit: January 13, 2025, 09:31:30 PM by Vortex »
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 313
  • Never be pleased, always improve
Re: Retrieving the version of an exe\dll
« Reply #5 on: January 13, 2025, 03:27:22 PM »
Windows Button + R and enter Winver
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 942
    • http://www.vortex.masmcode.com
Re: Retrieving the version of an exe\dll
« Reply #6 on: January 13, 2025, 09:33:21 PM »
Hi Philippe,

The tool is intended to get the version of an executable, not the version of the operating system.
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2189
Re: Retrieving the version of an exe\dll
« Reply #7 on: January 14, 2025, 09:12:34 AM »
In Windows 10 x64 i got this from ntdll.dll
Code: [Select]
10.0.19041.3996If someone prefer C
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "version.lib")

// __declspec(dllimport) int __cdecl printf(char *, ...); // for msvcrt.dll

int __cdecl main(int argc, char **argv)
{
VS_FIXEDFILEINFO *pffi;
BYTE bData[2048]; // just enough
DWORD dwSize = GetFileVersionInfoSize(argv[1], NULL);
if (dwSize) {
DWORD dwLen;
GetFileVersionInfo(argv[1], 0, dwSize, &bData);
VerQueryValue(&bData, "\\", (VOID*)&pffi,&dwLen);
// not using HIWORD, LOWORD
printf("%d.%d.%d.%d\n", pffi->dwFileVersionMS >> 16, pffi->dwFileVersionMS & 0xFFFF,
pffi->dwFileVersionLS >> 16, pffi->dwFileVersionLS & 0xFFFF);
}
return 0;
}
May the source be with you

Offline HellOfMice

  • Member
  • *
  • Posts: 313
  • Never be pleased, always improve
Re: Retrieving the version of an exe\dll
« Reply #8 on: January 14, 2025, 09:14:34 AM »
Hello Vortex,


Sorry I misunderstood


PhR
--------------------------------
Kenavo

Offline Vortex

  • Member
  • *
  • Posts: 942
    • http://www.vortex.masmcode.com
Re: Retrieving the version of an exe\dll
« Reply #9 on: January 14, 2025, 10:55:44 AM »
Hi Philippe,

No worries, it's OK.

Hi Timo,

Thanks for your code.
Code it... That's all...

Offline HellOfMice

  • Member
  • *
  • Posts: 313
  • Never be pleased, always improve
Re: Retrieving the version of an exe\dll
« Reply #10 on: January 14, 2025, 11:00:03 AM »
Have you tried by looking at into the Resources directory into the PE file?
--------------------------------
Kenavo

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2189
Re: Retrieving the version of an exe\dll
« Reply #11 on: January 14, 2025, 12:05:27 PM »
Not so easy to read from there, i prefer Win32 API functions  ;D
Code: [Select]
pFile  00 01 02 03 04 05 06 07  08 09 0A 0B 0C 0D 0E 0F Value           
000DE6F0 8C 03 34 00 00 00 56 00  53 00 5F 00 56 00 45 00 Œ.4...V.S._.V.E.
000DE700 52 00 53 00 49 00 4F 00  4E 00 5F 00 49 00 4E 00 R.S.I.O.N._.I.N.
000DE710 46 00 4F 00 00 00 00 00  BD 04 EF FE 00 00 01 00 F.O.....½.ïþ....
000DE720 01 00 06 00 E1 5F B1 1D  01 00 06 00 E1 5F B1 1D ....á_±.....á_±.
000DE730 3F 00 00 00 00 00 00 00  04 00 04 00 02 00 00 00 ?...............
000DE740 00 00 00 00 00 00 00 00  00 00 00 00 EA 02 00 00 ............ê...
000DE750 01 00 53 00 74 00 72 00  69 00 6E 00 67 00 46 00 ..S.t.r.i.n.g.F.
000DE760 69 00 6C 00 65 00 49 00  6E 00 66 00 6F 00 00 00 i.l.e.I.n.f.o...
000DE770 C6 02 00 00 01 00 30 00  34 00 30 00 39 00 30 00 Æ.....0.4.0.9.0.
000DE780 34 00 42 00 30 00 00 00  4C 00 16 00 01 00 43 00 4.B.0...L.....C.
000DE790 6F 00 6D 00 70 00 61 00  6E 00 79 00 4E 00 61 00 o.m.p.a.n.y.N.a.
000DE7A0 6D 00 65 00 00 00 00 00  4D 00 69 00 63 00 72 00 m.e.....M.i.c.r.
000DE7B0 6F 00 73 00 6F 00 66 00  74 00 20 00 43 00 6F 00 o.s.o.f.t. .C.o.
000DE7C0 72 00 70 00 6F 00 72 00  61 00 74 00 69 00 6F 00 r.p.o.r.a.t.i.o.
000DE7D0 6E 00 00 00 42 00 0D 00  01 00 46 00 69 00 6C 00 n...B.....F.i.l.
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 942
    • http://www.vortex.masmcode.com
Re: Retrieving the version of an exe\dll
« Reply #12 on: January 14, 2025, 03:12:40 PM »
I agree with Timo, the API function GetFileVersionInfo should do the job.
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 942
    • http://www.vortex.masmcode.com
Re: Retrieving the version of an exe\dll
« Reply #13 on: January 16, 2025, 08:07:15 PM »
File version information with Powershell :

Code: [Select]
(Get-Command C:\windows\system32\ntdll.dll).FileVersionInfo
Code: [Select]
.FileVersion
6.1.7600.16385 (win7_rtm.090713-1255)
Code it... That's all...