Class WindowsVersion

java.lang.Object
com.iizix.os.WindowsVersion

public final class WindowsVersion extends Object
The Windows version of a host: client or Server, the product ("Windows 11", "Windows Server 2025"), the release designation ("25H2"), the build and its update revision.

Where the values come from. The Java VM gives os.name and os.version, and its os.version is "10.0" on Windows 10, on Windows 11 and on every Windows Server since 2016 alike. The build, its update revision (UBR), the release designation (DisplayVersion; ReleaseId on a Windows from before DisplayVersion existed) and the installation type (client or Server) are in the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion. They are read with reg.exe query, one call per value and all started together, by the absolute path of reg.exe in the System32 directory of the Windows directory (no look-up along the path) and under one time limit. No other value of the key is read. The key's ProductName is of no use to tell Windows 10 from Windows 11: it says "Windows 10" on both.

The decision. A client is Windows 11 from build 22000 on and Windows 10 from build 10240 on. A Server is named by its build: 14393 is Windows Server 2016, 17763 is 2019, 20348 is 2022 and 26100 is 2025 (Microsoft's release information pages, read 2026-11-13). A Server of any other build is "Windows Server (build N)" and a client older than build 10240 is "Windows (build N)": a year or a name is never guessed. The release designation is what the registry holds, or empty: there is no table of builds and releases here, which every Windows release would make stale (and their order is not the order of the builds: 26H1 is build 28000, 26H2 is build 26300).

When the registry cannot be read (no reg.exe, the time limit, no build in its answer), the Java VM's own os.name and os.version are the answer, build is zero and problem says why.

Nothing here depends on another IIZI class: the static initializer of com.iizix.SystemConfig calls get(), so this class must never touch a class that needs SystemConfig.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The build, e.g.
    final boolean
    Flag for a Windows Server, false for a client.
    final String
    Why the registry could not be read, null when it was read.
    final String
    The product: "Windows 10", "Windows 11", "Windows Server 2016", "Windows Server 2019", "Windows Server 2022", "Windows Server 2025", "Windows Server (build N)" for a Server of another build, "Windows (build N)" for a client older than Windows 10, or the Java VM's os.name when the registry could not be read.
    final String
    The release designation as the registry holds it, e.g.
    final int
    The update revision of the build (UBR), e.g.
    final float
    The version as a number to compare with: 10.0 for Windows 10 and Windows Server 2016 to 2022, 11.0 for Windows 11 and for Windows Server 2025 or newer.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Gets the Windows version of this host.
    Gets the name part of the description toString(): the product without a build, e.g.
    Gets the version part of the description toString(): the release designation when known and the build with its update revision when known, e.g.
    Gets the description for a log line or a page: the product, the release designation when known, and the build with its update revision when known, e.g.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • isServer

      public final boolean isServer
      Flag for a Windows Server, false for a client.
    • product

      public final String product
      The product: "Windows 10", "Windows 11", "Windows Server 2016", "Windows Server 2019", "Windows Server 2022", "Windows Server 2025", "Windows Server (build N)" for a Server of another build, "Windows (build N)" for a client older than Windows 10, or the Java VM's os.name when the registry could not be read.
    • release

      public final String release
      The release designation as the registry holds it, e.g. "25H2", "24H2" or "1809"; empty when not known.
    • build

      public final int build
      The build, e.g. 26100; zero when the registry could not be read.
    • revision

      public final int revision
      The update revision of the build (UBR), e.g. 7171; -1 when not known.
    • version

      public final float version
      The version as a number to compare with: 10.0 for Windows 10 and Windows Server 2016 to 2022, 11.0 for Windows 11 and for Windows Server 2025 or newer. For a Windows older than Windows 10 it is the Java VM's os.version (6.3 for Windows 8.1), and zero when that cannot be parsed.
    • problem

      public final String problem
      Why the registry could not be read, null when it was read.
  • Method Details

    • get

      public static WindowsVersion get()
      Gets the Windows version of this host. The registry is read at the first call only.
      Returns:
      The version, null when this host is not Windows.
    • toString

      public String toString()
      Gets the description for a log line or a page: the product, the release designation when known, and the build with its update revision when known, e.g. "Windows 11 25H2 (build 26200.7171)", "Windows Server 2022 21H2 (build 20348.2700)" or "Windows Server 23H2 (build 25398.1085)". It is getName() and getVersionText() with a blank between them, so a page that shows the name and the version in two places shows this description.
      Overrides:
      toString in class Object
      Returns:
      The description.
    • getName

      public String getName()
      Gets the name part of the description toString(): the product without a build, e.g. "Windows 11", "Windows Server 2022", or "Windows Server" for a Server whose build has no name here (its build is in getVersionText()).
      Returns:
      The name.
    • getVersionText

      public String getVersionText()
      Gets the version part of the description toString(): the release designation when known and the build with its update revision when known, e.g. "25H2 (build 26200.7171)", "(build 25398.1085)" or "1809".
      Returns:
      The version part; empty when neither a release designation nor a build is known (the registry could not be read).