【发布时间】:2015-09-18 07:44:42
【问题描述】:
我一直在研究一种使用C# 获取当前系统操作系统的方法。
在许多情况下,似乎没有一个单一的答案,但它们似乎都有几年的历史了。我尝试使用的一些代码并以此为基础,不起作用。
所以我想出了自己的代码:
var os = System.Environment.OSVersion;
string currentOS = null;
switch(os.Platform)
{
case PlatformID.Win32S:
currentOS = "Windows 3.1";
break;
case PlatformID.Win32Windows:
switch(os.Version.Minor)
{
case 0:
currentOS = "Windows 95";
break;
case 10:
currentOS = "Windows 98";
break;
default:
currentOS = "Unknown";
break;
}
break;
case PlatformID.Win32NT:
switch(os.Version.Major)
{
case 3:
currentOS = "Windows NT 3.51";
break;
case 4:
currentOS = "Windows NT 4.0";
break;
case 5:
switch(os.Version.Minor)
{
case 0:
currentOS = "Windows 2000";
break;
case 1:
currentOS = "Windows XP";
break;
case 2:
currentOS = "Windows 2003";
break;
default:
currentOS = "Unknown";
break;
}
break;
case 6:
switch(os.Version.Minor)
{
case 0:
currentOS = "Windows Vista";
break;
case 1:
currentOS = "Windows 2008";
break;
case 2:
currentOS = "Windows 7";
break;
default:
currentOS = "Unknown";
break;
}
break;
default:
currentOS = "Unknown";
break;
}
break;
case PlatformID.WinCE:
currentOS = "Windows CE";
break;
case PlatformID.Unix:
currentOS = "Unix";
break;
default:
currentOS = "Unknown";
break;
}
我在运行 Windows 7 的笔记本电脑上测试了此代码,它返回 windows 2008。这可能是什么原因,有什么我应该改变的吗?
【问题讨论】:
-
代码完全是错误的,它是说6.1版本是
Windows 2008而不是Windows 7。它也无法以任何方式处理Windows 8。# -
好吧,Windows 7 是 NT 6.1 以及 Windows Server 2008 R2。查看此列表以获取更多信息:List of Microsoft Windows versions
标签: c#