Skip over navigation

Welcome to the all new DelphiDabbler website.

I hope you like it.

There are going to be bugs. Please report any you find on the website's issues page (GitHub account required). Thanks.

Click the close button and you won't see this message again.

System Information Unit

Gets information about the host computer and operating system

Version 5.4.0
Released 19 Mar 2020
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.4.0.zip.

Download v5.4.0

System Information Unit is a sub-project of the DDabLib project which is maintained in a Subversion repository. The code is developed in the trunk/projects/sysinfo branch.

Subversion users can check out the source code of the current release from the repository on SourceForge by doing:

svn checkout http://svn.code.sf.net/p/ddablib/code/tags/projects/sysinfo/release-5.4.0 codedir

where codedir is the directory where you want to checkout code. To check out other versions, simply specify a different version number.

The latest development tree can be checked out using:

 svn checkout http://svn.code.sf.net/p/ddablib/code/trunk/projects/sysinfo codedir

Check outs are read only, but you can easily contribute code: see Feedback & Queries below.

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.htm – read-me file.
  • ChangeLog.txt – 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

The project's change log can be viewed on SourceForge

A read-me file (ReadMe.htm) is included in the project download.

Feedback & Queries

If you find any bugs or want to suggest a new feature please report them using the Issue Tracker.

Click the Create Ticket button to create a ticket then complete the form giving as much information as possible.

The issue tracker is shared among all the projects in the DelphiDabbler Code Library, so please make sure you enter sysinfo in the Project edit box to make it clear which project you are referring to. You should also choose Defect in the Type drop down list to report a bug or Enhancement to request a new feature.

If you have created a bug fix or have implemented a new feature please attach a zip file to your ticket that contains your source code.

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-2020 by Peter Johnson. The source code is made available under the terms of the Mozilla Public License v2.0. All relevant trademarks are acknowledged.

The following people contributed to the development of the code:

  • Guillermo Fazzolari – bug fix in v2.0.1.
  • Laurent Pierre – provided many PRODUCT_* constants and suggested the GetProductInfo API code used in v3.0 and later.
  • Rich Habedank – bug fix in r228 and testing of bug fixes reported as issue #31 and issue #33.

The project also draws on the work of:

  • Achim Kalwa who translated the versionhelpers.h header into Pascal. Some of the IsReallyWindowsXXXXOrGreater methods of TPJOSInfo and the TestWindowsVersion routine are based closely on his work.
  • Brendan Grant for his ideas presented in this Code Project article.
  • Kendall Sullivan for the code on which TPJComputerInfo.IsAdmin is based. See here.
  • norgepaul for the code on which TPJComputerInfo.IsUACActive is based. See his answer to a question on Stack Overflow.