如何区分从Windows的客户端版本的服务器版本? [英] How to distinguish the server version from the client version of Windows?
本文介绍了如何区分从Windows的客户端版本的服务器版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何区分从Windows的客户端版本的服务器版本?
例:XP,Vista中,7 VS Win2003的,的Win2008
UPD:需要一种方法,如
布尔IsServerVersion()
{
返回...;
}
解决方案
好吧,亚历克斯,它看起来就像你可以使用WMI发现这一点:
使用System.Management;
公共BOOL IsServerVersion()
{
变种productType =新ManagementObjectSearcher(SELECT * FROM Win32_OperatingSystem)
获得()OfType<的ManagementObject>()
。选择(O =>(UINT)o.GetPropertyValue(ProductType))一()。
// ProductType将其中:
// 1:工作站
// 2:域控制器
// 3:服务器
返回productType = 1!;
}
您需要在您的项目中System.Management程序集的引用。
还是.NET 2.0的版本没有任何LINQ型的特点:
公共BOOL IsServerVersion()使用
{
(ManagementObjectSearcher搜索=新ManagementObjectSearcher(SELECT * FROM Win32_OperatingSystem))
{
的foreach(的ManagementObject的ManagementObject在searcher.Get( ))
{
// ProductType将其中:
// 1:工作站
// 2:域控制器
// 3:服务器
UINT productType =(UINT)managementObject.GetPropertyValue(ProductType);
返回productType = 1!;
}
}
返回FALSE;
}
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 ...;
}
解决方案
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;
}
这篇关于如何区分从Windows的客户端版本的服务器版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文