tags:

views:

125

answers:

2

System.Environment.OSVersion does not appear to indicate which Edition of Windows 2003 is installed (Standard, Enterprise, DataCenter).

Is there any way to access this information using managed code only?

I know I can use P/Invoke to call GetVersionEx and examine OSVERSIONINFOEX.wSuiteMask to get this info, but I'm looking for a simpler solution.

Update

Using WMI looks like the way to go, though the OSProductSuite property of Win32_OperatingSystem looks more reliable than the Name property. Here's sample code:

ManagementScope scope = new ManagementScope();
ObjectQuery query = new ObjectQuery("SELECT name, csdversion, description, OperatingSystemSKU, OSProductSuite FROM Win32_OperatingSystem");

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
    using (ManagementObjectCollection resultCollection = searcher.Get())
    {
        foreach (ManagementObject result in resultCollection)
        {
            foreach (PropertyData propertyData in result.Properties)
            {
                Debug.WriteLine(
                    propertyData.Name + ": " +
                    ((propertyData.Value == null) ? "" : propertyData.Value.ToString())
                    );
            }
        }
    }
}
A: 

I'm not aware of any way to do this using only managed code.

There is some code here using GetVersionEx that should encapsulate things for you nicely though.

Cocowalla
+3  A: 

You could execute the following WMI query:

SELECT name FROM Win32_OperatingSystem

It returns something like this:

Microsoft Windows Server 2003 Standard Edition|C:\WINDOWS|\Device\Harddisk0\Partition1

This article explains how to perform WMI queries using .NET.

fmunkert
Will try this, thanks
Joe
WMI gets my vote too :)
Cocowalla