[英]How to distinguish the server version from the client version of Windows?
How to distinguish the server version from the client version of Windows?如何区分Windows的服务端版本和客户端版本? Example: XP, Vista, 7 vs Win2003, Win2008.示例:XP、Vista、7 与 Win2003、Win2008。
UPD: Need a method such as UPD:需要一种方法,例如
bool IsServerVersion()
{
return ...;
}
Ok, Alex, it looks like you can use WMI to find this out:好的,亚历克斯,看起来你可以使用 WMI 来找出这个:
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.您需要引用项目中的 System.Management 程序集。
Or the .NET 2.0 version without any LINQ-type features:或者没有任何 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;
}
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.您可以通过检查注册表中的 ProductType 来执行此操作,如果它是 ServerNT,则您在 windows 服务器系统上;如果它是 WinNT,则您在工作站上。
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 }
There is no special flag for server windows versions, you need to check version IDs.服务器 windows 版本没有特殊标志,您需要检查版本 ID。 Take a look on tables in article: http://www.codeguru.com/cpp/wp/system/systeminformation/article.php/c8973查看文章中的表格: http://www.codeguru.com/cpp/wp/system/systeminformation/article.php/c8973
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.