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:

Popularity: 20% [?]

Related posts:

  1. Determine if Your C# Application is 64-bit
  2. Determine the Version of a Loaded .NET Assembly
  3. Determine the .NET Versions on which an Application is Compiled and Running
  4. Windows SDK for Windows 7 and .NET Framework 3.5 SP1: RC
  5. Determine if a Loaded .NET Assembly is Signed