Mike Goatly..
6
好的,Alex,看起来你可以使用WMI找到它:
using System.Management;
public bool IsServerVersion()
{
var productType = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
.Get().OfType()
.Select(o => (uint)o.GetPropertyValue("ProductType")).First();
// ProductType will be one of:
// 1: Workstation
// 2: Domain Controller
// 3: Server
return productType != 1;
}
您需要在项目中引用System.Management程序集.
或者没有任何LINQ类型功能的.NET 2.0版本:
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;
}