0

I need to detect what type (edition) of Windows OS is installed. By type I mean, for example: "Home", "Enterprise" or "Professional". Please don't ask why (I've already had that uphill-struggle with the requirement-wizards).

Right now the problem is that the Windows types seem to be localized, and I need a way to use them in a switch statement to do different behavior.

Right now I do this:

_os = (from x in new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>()
       select x.GetPropertyValue("Caption")).First().ToString().Trim();
switch (_os)
{   
    case "Microsoft Windows XP Professional":
        {
            // Do professional stuff...
            break;
        }
    case "Microsoft Windows 7 Professional":
    case "Microsoft Windows 7 Ultimate":
    case "Microsoft Windows 7 Enterprise":
        {
            // Do ultimate enterprisey professional stuff
            break;
        }
    default:
        {
            // File not found
            break;
        }
}

Anyone know how this could be done to not run into the issue of localization?

Amadeus Hein
  • 706
  • 1
  • 4
  • 12
  • Did you look here? http://www.codeproject.com/Articles/73000/Getting-Operating-System-Version-Info-Even-for-Win – Rafał Saltarski Mar 19 '13 at 07:38
  • I'd say it's not an exact duplicate (although I *had* missed that question), because the answers there include just getting the value -- but it may be localized, which I want to avoid and is my focus of this question. – Amadeus Hein Mar 19 '13 at 08:45

3 Answers3

0

On Codeproject is a nice article (with dll) to do this:

Getting Operating System Version Info - Even for Windows 8!

He get's his cheese from:

Determine Windows Version and Edition with C#

Erwin
  • 3,060
  • 26
  • 24
0

See OperatingSystemSKU property in Win32_OperatingSystem class, this is uint-based enumeration.

Dennis
  • 37,026
  • 10
  • 82
  • 150
0

You can P/Invoke the GetProductInfo native API. Usage and example in C# can be found here

Though its only supported in Vista and above.

Here is an example of how its done in C++ which can be easily P/Invoked

For XP, I don't think there is any way to get this info in a non-localized way I'm afraid.

Zaid Amir
  • 4,727
  • 6
  • 52
  • 101