Recent

Author Topic: Windows version  (Read 7814 times)

Mando

  • Full Member
  • ***
  • Posts: 181
Windows version
« on: January 05, 2011, 11:39:41 am »
Hello all:

I need to know the version of windows in wich my program runs.
How can i reach this?

regards.

typo

  • Hero Member
  • *****
  • Posts: 3051

jmnj

  • Newbie
  • Posts: 4
Re: Windows version
« Reply #2 on: June 17, 2020, 05:57:46 pm »
I use the recommendation from here...

https://wiki.freepascal.org/WindowsVersion

Worked for me.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Windows version
« Reply #3 on: June 17, 2020, 09:43:10 pm »
http://msdn.microsoft.com/en-us/library/ms724451%28v=vs.85%29.aspx

That doesn't work reliably anymore since Windows 8.1 onwards.  That same page explains why:

Quote
With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. The value returned by the GetVersionEx function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). Once an application is manifested for a given operating system version, GetVersionEx will always return the version that the application is manifested for in future releases.

If you don't manifest your app correctly, GetVersionEx() won't report the actual Windows version:

- If you don't manifest at all, it will report 8.0 when running on 8.1+.

- If you manifest only up to 8.1, it will report 8.1 when running on 10.0+.

- If you manifest only up to 10.0, it will report 10.0 when running on 10.1+.

And so on...

Every time a new version of Windows is released that requires a new manifest entry, you have to retest your app on that version and update your manifest accordingly so that Windows knows the app is compatible with that new version, otherwise Windows will dummy itself down for the version(s) that your app actually claims to support.

A more reliable way (for now) is to use RtlGetVersion() instead, as it is not subject to manifestation (yet?).

I use the recommendation from here...

https://wiki.freepascal.org/WindowsVersion

Worked for me.

That approach (using GetVersion()) is subject to the same manifest issue as GetVersionEx() on Windows 8.1 onward.
« Last Edit: June 17, 2020, 09:52:36 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Windows version
« Reply #4 on: June 17, 2020, 09:46:16 pm »
If you don't manifest your app correctly then you won't get a correct version reported.
Applications on Lazarus have the correct manifest.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Windows version
« Reply #5 on: June 17, 2020, 09:55:08 pm »
Applications on Lazarus have the correct manifest.

So, every time a new Windows is released that requires a new manifest entry, Lazarus is updated to add that entry automatically?

It really should not be Lazarus' responsibility to manage the OS version entries of the manifest.  The user should do that manually, based on the OS versions that they have actually tested their app on.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Windows version
« Reply #6 on: June 17, 2020, 10:19:17 pm »
So, every time a new Windows is released that requires a new manifest entry, Lazarus is updated to add that entry automatically?
Yes. It's normal.
Quote
It really should not be Lazarus' responsibility to manage the OS version entries of the manifest.
Lazarus makes sure that the app works correctly even in the latest versions. This is also normal.

RtlGetVersion this is a very special function for applications that for some reason do not have a manifest or deliberately hide from the OS about their ability to work with the latest versions.
« Last Edit: June 17, 2020, 10:22:43 pm by ASerge »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Windows version
« Reply #7 on: June 18, 2020, 03:14:54 am »
Lazarus makes sure that the app works correctly even in the latest versions. This is also normal.

Well, that does require users to update to a new Lazarus after it has been updated to support a new Windows version.  Not everyone upgrades right away.  And besides, just because the RTL/LCL frameworks that Lazarus provides work with certain Windows versions, doesn't necessarily mean that user's code does.  Hence why users should test their apps and then configure their manifests accordingly.

RtlGetVersion this is a very special function for applications that for some reason do not have a manifest or deliberately hide from the OS about their ability to work with the latest versions.

I have no idea what you are trying to say.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Windows version
« Reply #8 on: June 18, 2020, 09:29:27 am »
RtlGetVersion this is a very special function for applications that for some reason do not have a manifest or deliberately hide from the OS about their ability to work with the latest versions.

I have no idea what you are trying to say.

I think he refers to the point that RtlGetVersion like nearly all functions provided by NtDll are considered undocumented for the userspace. Thus by using them it might be that Microsoft changes them without you noticing (though to be fair considering Microsoft's backwards compatibility track record that is rather unlikely).

I agree however that Lazarus should provide more options to influence the manifest. Well, patches welcome I guess. ;)

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: Windows version
« Reply #9 on: June 18, 2020, 02:05:49 pm »
Just in case the OP might be interested.  The only Windows API that is known to always return the unadulterated truth about its version number is RtlGetNtVersionNumbers. 

Other APIs will either return what the program wants to "hear" or what Windows wants the program to "hear" and, neither may be the actual Windows version.

More information about that function is found in the thread https://forum.lazarus.freepascal.org/index.php/topic,46969.msg335900.html#msg335900

HTH.
« Last Edit: June 18, 2020, 02:08:47 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Windows version
« Reply #10 on: June 19, 2020, 02:04:27 am »
Just in case the OP might be interested.  The only Windows API that is known to always return the unadulterated truth about its version number is RtlGetNtVersionNumbers. 

Good catch, I forgot about that function.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: Windows version
« Reply #11 on: December 07, 2020, 05:32:33 am »
Hi friend, here I share the code I use

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. begin
  3.   If (Win32MajorVersion=10) and (Win32MinorVersion=0) then ShowMessage('Tienes Windows 10');
  4.   if (Win32MajorVersion=6) and (Win32MinorVersion=3) then ShowMessage('Tienes Windows 8.1');
  5.   if (Win32MajorVersion=6) and (Win32MinorVersion=2) then ShowMessage('Tienes Windows 8');
  6.   if (Win32MajorVersion=6) and (Win32MinorVersion=1) then ShowMessage('Tienes Windows 7');
  7.   if (Win32MajorVersion=6) and (Win32MinorVersion=0) then ShowMessage('Tienes Windows Vista');
  8.   if (Win32MajorVersion=5) and (Win32MinorVersion=1) then ShowMessage('Tienes Windows XP');
  9. End;

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Windows version
« Reply #12 on: December 07, 2020, 12:44:14 pm »
(I happened to be working on a fairly recent (created august) gui project, and there the manifest is off it seems, and I assume that is the default.)

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Windows version
« Reply #13 on: December 07, 2020, 03:02:03 pm »
Would the console command "systeminfo" help?
Code: [Select]
C:\lazarus\trunk\lazarus\examples\mousebuttons>systeminfo

Hostname:                                      SIXCORE
Betriebssystemname:                            Microsoft Windows 10 Pro
Betriebssystemversion:                         10.0.19041 Nicht zutreffend Build 19041
Betriebssystemhersteller:                      Microsoft Corporation
Betriebssystemkonfiguration:                   Eigenständige Arbeitsstation
Betriebssystem-Buildtyp:                       Multiprocessor Free
Registrierter Benutzer:                        peter
Registrierte Organisation:
Produkt-ID:                                      // I removed this ;)
Ursprüngliches Installationsdatum:             19.11.2020, 17:52:47
Systemstartzeit:                               01.12.2020, 19:52:55
Systemhersteller:                              Acer
Systemmodell:                                  Aspire M3300
Systemtyp:                                     x64-based PC
Prozessor(en):                                 1 Prozessor(en) installiert.
                                               [01]: AMD64 Family 16 Model 10 Stepping 0 AuthenticAMD ~2600 MHz
BIOS-Version:                                  American Megatrends Inc. P03-B4, 18.08.2010
Windows-Verzeichnis:                           C:\WINDOWS
System-Verzeichnis:                            C:\WINDOWS\system32
Startgerät:                                    \Device\HarddiskVolume2
Systemgebietsschema:                           de;Deutsch (Deutschland)
Eingabegebietsschema:                          de;Deutsch (Deutschland)
Zeitzone:                                      (UTC+01:00) Brüssel, Kopenhagen, Madrid, Paris
Gesamter physischer Speicher:                  7.934 MB
Verfügbarer physischer Speicher:               3.097 MB
Virtueller Arbeitsspeicher: Maximale Größe:    16.126 MB
Virtueller Arbeitsspeicher: Verfügbar:         6.503 MB
Virtueller Arbeitsspeicher: Zurzeit verwendet: 9.623 MB
[snip]
« Last Edit: December 07, 2020, 03:07:03 pm by Peter H »

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Windows version
« Reply #14 on: December 07, 2020, 05:55:48 pm »
Hi friend, here I share the code I use

The Win32(Major|Minor)Version variables use values from GetVersionEx(), and so are subject to the app's manifest, thus allowing Windows to lie about their values on Win8.1+.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018