How to distinguish the server version from the client version of Windows?
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;
}
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 }