This article explains how to use C# to determine the name, edition, service pack, version and bits of the host operating system.

For example, the results on my PC would be:

Operation System Information
—————————-
Name = Windows Vista
Edition = Home Premium
Service Pack = Service Pack 1
Version = 6.0.6001.65536
Bits = 64

Code

You can download the code here.

Sample Program

Here is a simple console program that demonstrates this:

using System; 

namespace CSharp411
{
    class Program
    {
        static void Main( string[] args )
        {
            Console.WriteLine( "Operation System Information" );
            Console.WriteLine( "----------------------------" );
            Console.WriteLine( "Name = {0}", OSInfo.Name );
            Console.WriteLine( "Edition = {0}", OSInfo.Edition );
            Console.WriteLine( "Service Pack = {0}", OSInfo.ServicePack );
            Console.WriteLine( "Version = {0}", OSInfo.VersionString );
            Console.WriteLine( "Bits = {0}", OSInfo.Bits );
            Console.ReadLine();
        }
    }
}

References

The code for this article was derived from some excellent articles on the subject:

Share and Enjoy:
  • Digg
  • Twitter
  • Facebook
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Google Bookmarks
  • Slashdot