C# - Operating System Information

The .NET Framework class library plays a crucial role in exposing features of the runtime and providing various high-level services for developers. Among the classes within the library, the OperatingSystem class stands out as it offers methods to copy an instance of OperatingSystem and retrieve a string representation of operating system information.

OperatingSystem class

It's important to note that the OperatingSystem class is not intended to be a general-purpose class. You cannot derive a more inclusive type from the OperatingSystem class. If you require a type to encompass additional information about an operating system, it is recommended to create your own custom type. You can include a field of type OperatingSystem within your custom type, along with any other fields, properties, or methods you need.

  1. System.Object
  2. System.OperatingSystem

To access information about the operating system within the .NET Framework, you can utilize the Environment class. This class exposes a property called OSVersion, which returns an object of type OperatingSystem. By accessing this property, you can retrieve information about the operating system on which your application is running. The returned OperatingSystem object provides details such as the version, service pack, and platform of the operating system.

OperatingSystem _os = null; _os = Environment.OSVersion;

Displaying this information with the console statements becomes possible by using the Environment class and its OSVersion property to create the OperatingSystem object and then access the Operating system within your application. The below mentioned C# program gets the details about software, such as it's version and platform identifier, using the Operating System Class and environment Class.

Full Source C#
using System; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OperatingSystem _os = null; _os = Environment.OSVersion; MessageBox.Show (_os.VersionString.ToString()); } } }


It is worth mentioning that the .NET Framework class library offers a wide range of classes and functionalities beyond the OperatingSystem class and the Environment class. Exploring the library will provide you with numerous other services and capabilities to enhance your application development process.