Get the computer's operating system in C#

This example uses the following code to display the operating system version when it starts.
private void Form1_Load(object sender, EventArgs e)
{
    OperatingSystem os_info = System.Environment.OSVersion;
    lblOs.Text = os_info.VersionString;
}

This example simply gets the System.Environment.OSVersion object and displays its VersionString property.

The OperatingSystem object has some other properties that may be useful in some programs.

  • Platform - Get a platform enumeration that can be one of Win32S (a Win32 layer in 16-bit windows), Win32Windows (Win95 or Win98), Win32NT WinNT or later), WinCE, Unix, or Xbox.
  • ServicePack - The service pack number as in "Service Pack 2."
  • Version - The operating system version numbers. This property includes the sub-properties Build, Major, MajorRevision, Minor, and MinorRevision.

You can translate the platform ID, major version, and minor version into the operating system (see How to determine the Windows version by using Visual C# for information) but it's a big hassle. It's much easier to just use the VersionString if you can.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.