Feb 03
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:
- CodeGuru article by Marius Bancila
- CodeProject article by Sabin Finateanu
- MSDN Documentation on GetProductInfo Function
Popularity: 20% [?]
Related posts:

Awesome! Plugged it right in and it worked. Thanks for providing it.
wonderful!thanks this code is very helpful.
Hi, thanks for this – Works a treat for Operating System's up to Vista. For it to detect Windows 7, I amended the Windows Vista Detection to look like this:
case 6:
switch (minorVersion)
{
case 0:
name = "Windows Vista";
break;
case 1:
name = "Windows 7″;
break;
case 3:
name = "Windows Server 2008″;
break;
}
break;
Seems to work a treat, but haven't tested on Windows Vista. I now want to know how I would go about fixing the Product part, so it will show 'Professional' etc. (I think Home Premium, Basic and Ultimate should still be working).
Any help is appreciated
Have you a way of discriminating between XP Professional and XP Tablet?
Ok I have found it!!
To discriminate if you have a Tablet PC running XP
Inside #region EDITION I added
[DLLImport("user32")]
public static extern int GetSystemMetrics(int nIndex);
and
in #region 5 made this change
if ((suitMask & VER_SUITE_PERSONAL) != 0)
{
edition = "Home";
}
else
{
if (GetSystemMetrics(86) == 0) // 86 == SM_TABLETPC
edition = "Professional";
else
edition = "Tablet Edition";
}
I was able to test only on an XP Tablet and an XP Professional laptops.
Thanks for a terrific article and Jonney Tiney fb.