gpt4 book ai didi

c# - 从 XP 及更高版本获取 Windows 操作系统名称

转载 作者:行者123 更新时间:2023-12-04 17:17:51 24 4
gpt4 key购买 nike

我正在尝试弄清楚如何获取 Windows 8 的操作系统名称。我目前正在使用以下代码,但它不处理 Windows 7 或 Windows 8。

如何处理更新的 Windows 版本?

System.OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;

if (os.Platform == PlatformID.Win32Windows)
{
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;
}
}
MessageBox.Show("operating System: " + operatingSystem +
"\nOS Version: " + os.Version.ToString() +
"\nOS Platoform: " + os.Platform.ToString() +
"\nOS SP: " + os.ServicePack.ToString() +
"\nOS Version String: " + os.VersionString.ToString());

最佳答案

从 Windows Vista 开始,版本的主要编号为 6。 Windows Vista 有 6.0,Windows 7 有 6.1,Windows 8 有 6.2

参见 here概览。

编辑

switch (vs.Major)
{
case 3:
Console.WriteLine("Windows NT 3.51");
break;
case 4:
Console.WriteLine("Windows NT 4.0");
break;
case 5:
if (vs.Minor == 0)
Console.WriteLine("Windows 2000");
else
Console.WriteLine("Windows XP");
break;
case 6:
if(vs.Minor == 0)
Console.WriteLine("Windows Vista");
else if(vs.Minor == 1)
Console.WriteLine("Windows 7");
else if(vs.Minor == 2)
Console.WriteLine("Windows 8")
break;
}

关于c# - 从 XP 及更高版本获取 Windows 操作系统名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15668190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com