Skip over navigation

System Information Unit

Gets information about the host computer and operating system

Version 5.30.0
Released 2024-10-06
Platforms Win32 & Win64
Framework RTL
Compatibilty Delphi 7 & later

Overview

This unit contains a group of static classes and some global variables that provide information about the user's computer system and operating system. Some useful constants and type definitions are also included. The static classes are:

TPJComputerInfo
Provides information about the host computer and current user.
TPJSystemFolders
Gets the full path of certain system folders.
TPJOSInfo
Supplies information about the operating system including the platform, product name, product ID, version and service packs.

In addition, the unit extends the information provided by the SysUtils unit's Win32xxx variables (such as Win32Platform) by defining further Win32xxx variables that store the extended operating system information available on later NT platform OSs.

With the introduction of Windows 8.1 Microsoft deprecated the GetVersion and GetVersionEx API functions that PJSysInfo uses to get operating system version information. These API functions always return information about the reported operating system, which, when the program is running in compatibility mode, may be different to the true operating system. Furthermore GetVersion will not detect Windows 8.1 correctly in all cases.

From version 5 of the unit, to avoid using the deprecated API functions, a different approach is used to obtain version information when running on Windows 8.1 or later. This new method always returns information about the true operating system, regardless of any compatibility mode.

These changes mean that some of TPJOSInfo's methods and some global variables are affected by compatibility mode when run on operating systems prior to Windows 8.1, but will ignore compatibility mode on Windows 8.1 and later.

To help decide if compatibility mode will affect the returned information the TPJOSInfo.CanSpoof method was added in v5.0.

It is unfortunate that the class's behaviour is no longer consistent across operating systems, but there is no choice if the code is to abide by Microsoft's much criticised decision to deprecate and possibly remove the old API.

v5.0 also adds some new methods to TPJOSInfo that can be used to detect operating systems that always ignore compatibility mode – i.e. they can't be spoofed.

In summary, there are several inconsistencies in TPJOSInfo all because of some incomprehensible decisions made by Microsoft. They are:

  • On OSs up to and including Windows 7 SP 1 the reported operating system can be "spoofed" by setting the host program's compatibility mode. The exception is that the TPJOSInfo.IsReallyWindowsXXXOrGreater methods for Windows 2000 and later will detect the actual operating system.
  • For Windows 8 and 8.1 the reported operating system cannot be spoofed using compatibility modes, and neither does the presence of a suitable manifest file affect the returned values. This also applies to the relevant TPJOSInfo.IsReallyWindowsXXXOrGreater methods.
  • For Windows 10 the reported operating system cannot be spoofed regardless of whether a suitable manifest is compiled into resource. However, in absence of a such a manifest the version will be always be reported as Windows 8 instead of Windows 10. This also affects TPJOSInfo.IsReallyWindows10OrGreater, meaning it's not so well named any more!

After exploring and testing a lot of options this really is the best solution I can find. Thanks a bundle Microsoft!

For the final word on this, see the project documentation.

The stated compatibilty for the unit is Delphi 7 & later. However it is possible that the unit may compile with earlier versions.

But be warned, there is a known issue with some of these old versions in that they do not support setting registry access flags via the TRegistry object. This means that some of this code may not work correctly when running 32 bit programs on 64 bit Windows.

Consequently, using Delphi 6 or earlier is not recommended and is not supported.

Version 2 and earlier of the unit provided the TPJSysInfo component and various SIGetxxx functions. As of v3.0 these were deprecated and included only if a certain symbol was defined. From v4.0 all the deprecated code was removed.

If you are still using the deprecated code you need to update your code to use the new classes.

Two demo projects are included in the download in the Demos\VCL and the Demos\FMX directories. The former compiles to a VCL application while the latter uses the FireMonkey 2 framework and requires Delphi XE3 as a minimum. Both projects can be compiled to either Windows 32 bit or 64 bit targets.

Each project contains a tab set where each tab displays the information from one of the classes or the global variables.

The VCL demo has been tested with Delphi XE and XE4 but should compile with Delphi 7 or later, although some unrecognised form properties may need to be ignored. The FireMonkey demo was tested with Delphi XE4.

Get The Code

You can download the latest version of the System Information Unit directly from SourceForge as dd-sysinfo-5.30.0.zip.

Download v5.30.0

The System Information Unit source code is hosted in the ddablib/sysinfo GitHub repository. You can git clone or fork the repository as required.

Installation

The System Information Unit is supplied in a zip file. Before installing you need to extract all the files from the zip file, preserving the directory structure. The following files will be extracted:

  • PJSysInfo.pas – the source code.
  • README.md – read-me file.
  • CHANGELOG.md – project change log.
  • MPL-2.txt – the Mozilla Public License v2.0.
  • Documentation.URL – short-cut to the unit's online documentation.

In addition to the above files you will find the source code of two demo projects and their read-me file in the Demos directory.

There are three possible ways to use the unit.

  1. The simplest way is to add PJSysInfo.pas to your projects as you need it.
  2. To make the unit easier to re-use you can either copy it to a folder on your Delphi search path, or add the folder where you extracted the unit to the search path. You then simply use the unit as required without needing to add it to your project.
  3. For maximum portability you can add the unit to a Delphi package. If you need help doing this see here.

Documentation

The System Information Unit is comprehensively documented online here

Read-me file: README.md

Change log: CHANGELOG.md.

Acknowledgements: Acknowledgements.md.

Feedback & Queries

If you find any bugs or want to suggest a new feature please report them using the System Information Unit issue tracker.

If you have created a bug fix or have implemented a new feature please open a pull request for it.

Should you have any queries about using the classes please read the documentation. If you can't find an answer in the documentation then post a message in the discussion group.

License & Credits

The System Information Unit is open source. It is copyright © 2001-2024 by Peter Johnson. The source code is made available under the terms of the Mozilla Public License v2.0. All relevant trademarks are acknowledged.

Information from numerous websites has been used while developing this code. Several individuals have also suggested solutions or contributed code. Details are provided in the file Acknowledgements.md in the .\Docs subdirectory of the System Information Unit's GitHub repository.