Reader Level:
How do I

Get Operating System Data and Version in C#

By Mahesh Chand on Feb 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.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 60.7k
  • 0

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());



            // 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);






The output will look like following: