有人可以帮我修改这段代码以支持 Windows 2003 和 Windows 2008 服务器吗? 谢谢
public static string getOSLegacy()
{
//Get Operating system information.
OperatingSystem os = Environment.OSVersion;
//Get version information about the os.
Version vs = os.Version;
//Variable to hold our return value
string operatingSystem = "";
if (os.Platform == PlatformID.Win32Windows)
{
//This is a pre-NT version of Windows
switch (vs.Minor)
{
case 0:
operatingSystem = "95";
break;
case 10:
if (vs.Revision.ToString() == "2222A")
operatingSystem = "98SE";
else
operatingSystem = "98";
break;
case 90:
operatingSystem = "Me";
break;
default:
break;
}
}
else if (os.Platform == PlatformID.Win32NT)
{
switch (vs.Major)
{
case 3:
operatingSystem = "NT 3.51";
break;
case 4:
operatingSystem = "NT 4.0";
break;
case 5:
if (vs.Minor == 0)
{
operatingSystem = "2000";
}
else
{
operatingSystem = "XP";
}
break;
case 6:
if (vs.Minor == 0)
{
operatingSystem = "Vista";
}
else
{
operatingSystem = "7";
}
break;
default:
break;
}
}
return operatingSystem;
}
最佳答案
在 Server 2003 上,版本返回 5.2.3790.131072。 在 Server 2008 上,版本返回 6.0.6002.131072。
(在 Windows 7 上是 6.1.7600.0)。
此外,您还可以从注册表中获取完整的操作系统名称:
HKLM\Software\Microsoft\Windows NT\CurrentVersion,关键产品名称。
关于c# - 在C#中检测windows 2008 server和windows 2003 server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3482195/