c# - 在C#中检测windows 2008 server和windows 2003 server

标签 c# operating-system

有人可以帮我修改这段代码以支持 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/

相关文章:

c# - 如何动态获取URL中的参数?

c# - XNA - 如何 "install"Lidgren?

JAVA 返回 "Linux-all-ports"作为 os.name。 "Linux"as os.name 相比有什么意义?

c - 常规文件上的 Kqueue

c - 不同的线程使用不同的策略进行调度

c# - .NET 6 Parallel.ForEachAsync 中需要两个 token 吗?

c# - 小pdf文件变成巨大的字节数组

c# - 在 ASP.NET MVC 2 项目中同时使用 Razor 和 Spark

c - 在运行前台进程时等待后台进程终止

python - 使用python的文件权限