如何以编程方式知道我的操作系统是Longhorn服务器还是Vista(客户端)。
看来主要版本和次要版本都是相同的两个:
http://msdn.microsoft.com/en-us/library/ms724833.aspx
那么,有没有更好的select?
不是你链接的同一页给你答案?
Windows server 2008 OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION Windows Vista OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
只需根据wProductType
检查wProductType
成员
编辑
看起来没有一个方法来得到这个没有P / Invoke。 System.Environment.OSVersion
没有公开这个级别的细节,尽管在mscorlib
中的Microsoft.Win32
命名空间中有一个internal static class Win32Native
,据反汇编我可以看出,没有什么东西可以使用,更不用说公开了, wProductType
。
我发现(但没有尝试) 在pinvoke.net这个页面 。
对于服务器,
OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
对于工作站
OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
您可以使用WMI来查找Windows版本以及各种其他系统信息。
以下是如何获取版本字符串:
var osDetails = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<System.Management.ManagementObject>().First(); string version = osDetails.GetPropertyValue("Caption") as string;
这将返回一个字符串,如下所示:“Microsoft Windows XP Professional”。
除了可用于检索版本号,版本,体系结构等的Caption之外,还有更多的属性:
http://msdn.microsoft.com/en-us/library/aa394239(v=VS.85).aspx