(c#)检测Windows操作系统类型(非本地化)
本文关键字:本地化 类型 Windows 检测 操作系统 | 更新日期: 2023-09-27 18:04:32
我需要检测安装的Windows操作系统类型(版本)。我说的类型是指,例如:"家庭"、"企业"或"专业"。请不要问为什么(我已经与需求向导进行了艰苦的斗争)。
现在的问题是Windows类型似乎是本地化的,我需要一种方法在switch语句中使用它们来执行不同的行为。
现在我这样做:
_os = (from x in new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>()
select x.GetPropertyValue("Caption")).First().ToString().Trim();
switch (_os)
{
case "Microsoft Windows XP Professional":
{
// Do professional stuff...
break;
}
case "Microsoft Windows 7 Professional":
case "Microsoft Windows 7 Ultimate":
case "Microsoft Windows 7 Enterprise":
{
// Do ultimate enterprisey professional stuff
break;
}
default:
{
// File not found
break;
}
}
有谁知道怎么做才能不遇到本地化问题?
On Codeproject是一篇很好的文章(带有dll):
获取操作系统版本信息-即使是Windows 8!
他的奶酪来自:
使用c#确定Windows版本和版本
参见Win32_OperatingSystem
类中的OperatingSystemSKU
属性,这是基于uint
的枚举
您可以p/调用GetProductInfo本机API。c#中的用法和示例可以在这里找到
虽然它只支持Vista及以上版本。
下面是一个c++的例子,可以很容易地p/Invoked
对于XP,我认为恐怕没有办法以非本地化的方式获得这些信息。