Monday, April 1, 2013

Get OS version in C# the easy way

Leave a Comment
c# os version

Hi, today im going to show you the easy way to get the OS version in C#. So Fire up Visual Studio and select new Console application project and Name in GetOSVersion.


  •  Add a reference to Microsoft.VisualBasic assembly.
  • Add Namespace
    //Import Namespace
    using Microsoft.VisualBasic.Devices;
  • Add below code in program class
            static void Main(string[] args)
            {
                //Create a new instance of computer class
                Computer com = new Computer();
                Console.WriteLine("OS Name: " + com.Info.OSFullName);
                Console.WriteLine("OS Version: " + com.Info.OSVersion);
                Console.WriteLine("OS Platform: " + com.Info.OSPlatform);
                Console.ReadLine();
             }
    
    
  • Done. :)

Below is full code of program class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Import Namespace
using Microsoft.VisualBasic.Devices;
namespace GetOSVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new instance of computer class
            Computer com = new Computer();
            Console.WriteLine("OS Name: " + com.Info.OSFullName);
            Console.WriteLine("OS Version: " + com.Info.OSVersion);
            Console.WriteLine("OS Platform: " + com.Info.OSPlatform);
            Console.ReadLine();
        }
    }
}

Hope you like this method.

0 comments:

Post a Comment