- 相關推薦
C#檢測操作系統版本的方法匯總
本文實例為大家分享了C#檢測操作系統版本的方法,供大家參考,具體內容如下
我們通過System.Environment.OSVersion.Version獲得操作系統的版本號,然后再根據版本號進行判斷操作系統是什么版本。
Version 類的屬性
參考于:https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms724834(v=vs.85).aspx
注意:在msdn官方文檔有說明 → OSVersion 屬性報告兩個相同的版本號 (6.2.0.0) 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){this.OSystemName = oSystemName;}public GetOSystem(){switch (System.Environment.OSVersion.Version.Major + "." + System.Environment.OSVersion.Version.Minor){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("Windows8.OrWindows8.1");break;case Windows10:setOSystemName("Windows10");break;}Console.WriteLine(OSystemName);}}class Program{static void Main(string[] args){#region 檢測系統new GetOSystem();#endregion}}
輸出結果:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。
【C#檢測操作系統版本的方法】相關文章:
c#檢測cpu使用率01-02
KMP算法的C#實現方法04-11
獲取當前操作系統的軟件版本08-11
Linux操作系統的十個經典版本08-01
WindowsMobile操作系統手機版本分類對應機型01-26
Linux查看系統版本的方法06-26
快速安裝操作系統的方法07-09
操作系統打補丁的方法06-04
unix操作系統關機方法04-12