有人可以幫我修改此代碼以支持Windows 2003和Windows 2008服務器? 謝謝檢測Windows 2008服務器和Windows 2003服務器在C#
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;
}
由於Windows 7和Server 2008 R2具有相同版本(6.1),並且Win XP 64位與Windows Server 2003具有相同版本,所以此答案爲垃圾。 – Stian 2012-06-21 06:08:41
同意。該答案包含虛假信息(以及鏈接的代碼):它指出Win7爲6.2,而Win8爲6.2 – Salaros 2013-01-26 18:46:25