user595809
user595809

Reputation:

How to distinguish the server version from the client version of Windows?

How to distinguish the server version from the client version of Windows? Example: XP, Vista, 7 vs Win2003, Win2008.

UPD: Need a method such as

bool IsServerVersion()
{
    return ...;
}

Upvotes: 7

Views: 3477

Answers (3)

Tommy
Tommy

Reputation: 370

You can do this by checking the ProductType in the registry, if it is ServerNT you are on a windows server system if it is WinNT you are on a workstation.

    using Microsoft.Win32;
    String strOSProductType = Registry.GetValue("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 
                                                "ProductType", 
                                                "Key doesn't Exist" ).ToString() ;
    if( strOSProductType == "ServerNT" )
    {
        //Windows Server
    }
    else if( strOsProductType == "WinNT" )
    {
        //Windows Workstation
    }

Upvotes: 2

Mike Goatly
Mike Goatly

Reputation: 7528

Ok, Alex, it looks like you can use WMI to find this out:

using System.Management;

public bool IsServerVersion()
{
    var productType = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
            .Get().OfType<ManagementObject>()
            .Select(o => (uint)o.GetPropertyValue("ProductType")).First();

    // ProductType will be one of:
    // 1: Workstation
    // 2: Domain Controller
    // 3: Server

    return productType != 1;
}

You'll need a reference to the System.Management assembly in your project.

Or the .NET 2.0 version without any LINQ-type features:

public bool IsServerVersion()
{
    using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"))
    {
        foreach (ManagementObject managementObject in searcher.Get())
        {
            // ProductType will be one of:
            // 1: Workstation
            // 2: Domain Controller
            // 3: Server
            uint productType = (uint)managementObject.GetPropertyValue("ProductType");
            return productType != 1;
        }
    }

    return false;
}

Upvotes: 8

Anton Semenov
Anton Semenov

Reputation: 6347

There is no special flag for server windows versions, you need to check version IDs. Take a look on tables in article: http://www.codeguru.com/cpp/w-p/system/systeminformation/article.php/c8973

Upvotes: 1

Related Questions