C#检测操作系统版本的方法汇总

博学站 人气:2.26W

本文实例为大家分享了C#检测操作系统版本的方法,供大家参考,具体内容如下

C#检测操作系统版本的方法汇总

我们通过ion获得操作系统的版本号,然后再根据版本号进行判断操作系统是什么版本。

Version 类的属性

参考于:(v=vs.85)

注意:在msdn官方文档有说明 → OSVersion 属性报告两个相同的版本号 () Windows 8 和 Windows 8.1。在某些情况下, OSVersion 属性可能不会返回与指定的' Windows 程序兼容性模式功能的版本相匹配的操作系统版本。

代码:

public class GetOSystem{private const string Windows2000 = "5.0";private const string WindowsXP = "5.1";private const string Windows2003 = "5.2";private const string Windows2008 = "6.0";private const string Windows7 = "6.1";private const string Windows8OrWindows81 = "6.2";private const string Windows10 = "10.0";private string OSystemName;public void setOSystemName(string oSystemName){temName = oSystemName;}public GetOSystem(){switch (r + "." + r){case Windows2000:setOSystemName("Windows2000");break;case WindowsXP:setOSystemName("WindowsXP");break;case Windows2003:setOSystemName("Windows2003");break;case Windows2008:setOSystemName("Windows2008");break;case Windows7:setOSystemName("Windows7");break;case Windows8OrWindows81:setOSystemName("ndows8.1");break;case Windows10:setOSystemName("Windows10");break;}eLine(OSystemName);}}class Program{static void Main(string[] args){#region 检测系统new GetOSystem();#endregion}}

输出结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。