Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Get OS Version


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Nov 24, 2015 7:28 AM Last Post By: Peter Below
Carlos Matos

Posts: 114
Registered: 6/25/01
Get OS Version  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2015 9:46 AM
How can I get OS Version, e.g., how can I get if I'm on Windows 10 or greater?
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Get OS Version  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2015 11:13 AM   in response to: Carlos Matos in response to: Carlos Matos
Carlos Matos wrote:

How can I get OS Version, e.g., how can I get if I'm on Windows 10 or
greater?

If your application has a manifest that declares that it is Win10
compatible GetVersionex will get the correct version, otherwise it will
shamelessly lie to you to presumable make your application think it
runs under a version it is compatible with.

The real question is: why do you care? If you want to use a specific OS
feature, test for the presence of the feature, not for a specific OS
version.

One such feature is the Version Helper API (see
https://msdn.microsoft.com/de-de/library/windows/desktop/dn424972%28v=vs
.85%29.aspx ). See especially the user comments at the end of that page.

--
Peter Below
TeamB

Carl Olsen

Posts: 124
Registered: 3/29/00
Re: Get OS Version  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2015 1:01 PM   in response to: Peter Below in response to: Peter Below
Peter: How do I let applications know I am Windows 10 compatible with a Manifest like you describe? I always just figured Delphi would do that for me. I"m using XE8, if that matters.

The real question is: why do you care? If you want to use a specific OS
feature, test for the presence of the feature, not for a specific OS
version.

Some reasons I care...

1 - We have a feature that bundles up settings and OS information as a report to send to tech support. Knowing the operating system is very useful to our support department, so we use TOSVersion.ToString to let them know within the report.

2 - Sometimes one may want to display things differently depending on the operating system. For example, show a different style of icon when on Vista than if in XP or Windows 10, or follow a different UI convention, etc.

3 - For legacy reasons. For example, when running code on an older system, do things the old way for backwards compatibility (even if not the "right" way), and do things the new way for newer systems.

4 - For installers, for example, to be able to say, "Sorry, this installer is not compatible with Windows XP and older".

So correct me if I am wrong, but I think there are plenty of valid reasons to want to know what OS you are running on, beyond just API calls.
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Get OS Version  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2015 7:28 AM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

Peter: How do I let applications know I am Windows 10 compatible with
a Manifest like you describe? I always just figured Delphi would do
that for me. I"m using XE8, if that matters.

Do a Google search for

manifest windows 10 site:forums.embarcadero.com

That will turn up a number of relevant threads, this is a recurrent
theme. XE8 allowed the use of a custom manifest but I don't know which
Windows version it cited in the stock manifest. XE8 is one of the
versions I have not installed on this new PC of mine.


The real question is: why do you care? If you want to use a
specific OS feature, test for the presence of the feature, not for
a specific OS version.

Some reasons I care...

which are quite valid, IMO.

1 - We have a feature that bundles up settings and OS information as
a report to send to tech support. Knowing the operating system is
very useful to our support department, so we use TOSVersion.ToString
to let them know within the report.

2 - Sometimes one may want to display things differently depending on
the operating system. For example, show a different style of icon
when on Vista than if in XP or Windows 10, or follow a different UI
convention, etc.

3 - For legacy reasons. For example, when running code on an older
system, do things the old way for backwards compatibility (even if
not the "right" way), and do things the new way for newer systems.

4 - For installers, for example, to be able to say, "Sorry, this
installer is not compatible with Windows XP and older".

So correct me if I am wrong, but I think there are plenty of valid
reasons to want to know what OS you are running on, beyond just API
calls.


--
Peter Below
TeamB

Carl Olsen

Posts: 124
Registered: 3/29/00
Re: Get OS Version  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2015 12:49 PM   in response to: Carlos Matos in response to: Carlos Matos
Carlos Matos wrote:
How can I get OS Version, e.g., how can I get if I'm on Windows 10 or greater?

I am not sure at what version of Delphi this became available, but TOSVersion in System.SysUtils is super handy for this, and works for Windows 10.

I know it works for XE8.

Examples:

ShowMessage(IntToStr(TOSVersion.Build));
ShowMessage (TOSVersion.ToString); // Super handy for displaying to user


Here is how it is declared:

type
  TOSVersion = record
  public type
    TArchitecture = (arIntelX86, arIntelX64, arARM32, arARM64);
    TPlatform = (pfWindows, pfMacOS, pfiOS, pfAndroid, pfWinRT, pfLinux);
  public const
    AllArchitectures = [arIntelX86, arIntelX64, arARM32, arARM64];
    AllPlatforms = [pfWindows, pfMacOS, pfiOS, pfAndroid, pfWinRT, pfLinux];
  private
    class var FArchitecture: TArchitecture;
    class var FBuild: Integer;
    class var FMajor: Integer;
    class var FMinor: Integer;
    class var FName: string;
    class var FPlatform: TPlatform;
    class var FServicePackMajor: Integer;
    class var FServicePackMinor: Integer;
    class constructor Create;
  public
    class function Check(AMajor: Integer): Boolean; overload; static; inline;
    class function Check(AMajor, AMinor: Integer): Boolean; overload; static; inline;
    class function Check(AMajor, AMinor, AServicePackMajor: Integer): Boolean; overload; static; inline;
    class function ToString: string; static;
    class property Architecture: TArchitecture read FArchitecture;
    class property Build: Integer read FBuild;
    class property Major: Integer read FMajor;
    class property Minor: Integer read FMinor;
    class property Name: string read FName;
    class property Platform: TPlatform read FPlatform;
    class property ServicePackMajor: Integer read FServicePackMajor;
    class property ServicePackMinor: Integer read FServicePackMinor;
  end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02