Reader Level:
Articles

Get Operating System Data and Version in C#

By Mahesh Chand on February 29, 2008
In one of my applications, I needed Operating System version, service pack and other details. Here is the code snippet that shows how to use the Environment class to get Operating System data.
  • 0
  • 0
  • 38152

The following code snippet displays your Operating System's version, SP, and platform details by using the OperatingSystem object and its members.

The Version class and its properties Major, Minor, and Build represent the major, minor, and build numbers.


using System;

 

namespace OsVersionSample

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Operating System Detaiils");

            OperatingSystem os = Environment.OSVersion;

            Console.WriteLine("OS Version: " + os.Version.ToString());

            Console.WriteLine("OS Platoform: " + os.Platform.ToString());

            Console.WriteLine("OS SP: " + os.ServicePack.ToString());

            Console.WriteLine("OS Version String: " + os.VersionString.ToString());

            Console.WriteLine();

 

            // Get Version details

            Version ver = os.Version;

            Console.WriteLine("Major version: " + ver.Major);

            Console.WriteLine("Major Revision: " + ver.MajorRevision);

            Console.WriteLine("Minor version: " + ver.Minor);

            Console.WriteLine("Minor Revision: " + ver.MinorRevision);

            Console.WriteLine("Build: " + ver.Build);

 

            Console.ReadLine();

        }

    }

}


The output will look like following:

OS.jpg




Mahesh Chand

Mahesh Chand is founder of C# Corner. C# Corner founded in 1999 is a FREE member contributions based open platform for developers to solve problems, learn new technology and hang out.  Mahesh has been awar... Read more

COMMENT USING

Trending up