This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

System Information
.NET 1.1+

Getting the Current Operating System Version

Each new version of Microsoft Windows includes an updated set of application programming interfaces (APIs). To ensure that a program only accesses API functions that are available, it is important to be able to detect the operating system version in use.

Environment Class

The Environment class is a standard class within the System namespace. It provides information relating to the current environment and operating system and, in some cases, allows the information to be modified. The Environment class contains a static property named OSVersion that returns information about the operating system that the program is executing within.

The OSVersion property returns an object of the OperatingSystem class. This class has several properties that are useful when examining the Windows version:

  • Platform. Holds a PlatformID enumeration value that represents the current operating system type. The possible platform values are listed in the table below.
  • Version. Holds the major version, minor version, build and revision version numbers for the operating system build. The major version can be used to determine the actual version of Windows in operation, or the compatibility mode in use. Wikipedia has a list of the Windows version numbers for reference purposes.
  • Service Pack. This property was introduced in .NET 2.0. It contains a string describing the current service pack level applied to the operating system.
  • VersionString. This .NET 2.0 property holds a string that combines the other three properties for display purposes.

Using Environment.OSVersion

The following code shows the use of the OSVersion property. The results displayed are those from the author's Windows Vista-based system with no service pack installed.

OperatingSystem os = Environment.OSVersion;
Console.WriteLine("Platform: {0}", os.Platform);
Console.WriteLine("Version:  {0}", os.Version);
Console.WriteLine("Svc Pack: {0}", os.ServicePack);
Console.WriteLine("VString:  {0}", os.VersionString);

Platform: Win32NT
Version:  6.0.6000.0
Svc Pack:
VString:  Microsoft Windows NT 6.0.6000.0


Platform ID Values

PlatformID.NET VersionDescription
Win32S1.1The operating system is Win32s, which allows 32-bit programs to execute in a 16-bit environment. This operating system does not support .NET so should never be returned by the OSVersion property.
Win32NT1.1Windows NT or later.
Win32Windows1.1Windows 95 or later. Only versions starting from Windows 98 support the .NET framework.
WinCE1.1Windows CE.NET or another Windows-based portable operating system, such as PocketPC or Windows Mobile.
Unix2.0The operating system is a Unix variant.
XBox3.5The operating system is running on Microsoft's XBox 360 games console.
21 January 2008