C#如何檢測(cè)操作系統(tǒng)版本
本文實(shí)例為大家分享了C#檢測(cè)操作系統(tǒng)版本的方法,供大家參考,具體內(nèi)容如下
我們通過System.Environment.OSVersion.Version獲得操作系統(tǒng)的版本號(hào),然后再根據(jù)版本號(hào)進(jìn)行判斷操作系統(tǒng)是什么版本。
Version 類的屬性


參考于:https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms724834(v=vs.85).aspx
注意:在msdn官方文檔有說明 → OSVersion 屬性報(bào)告兩個(gè)相同的版本號(hào) (6.2.0.0) Windows 8 和 Windows 8.1。在某些情況下, OSVersion 屬性可能不會(huì)返回與指定的 Windows 程序兼容性模式功能的版本相匹配的操作系統(tǒng)版本。
代碼:
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 檢測(cè)系統(tǒng)
new GetOSystem();
#endregion
}
}
輸出結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
c# 如何實(shí)現(xiàn)不同進(jìn)程之間的通信
這篇文章主要介紹了c# 如何實(shí)現(xiàn)不同進(jìn)程之間的通信,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下2020-11-11
DataGridView自定義單元格表示值、Error圖標(biāo)顯示的方法介紹
這篇文章介紹了DataGridView自定義單元格表示值、Error圖標(biāo)顯示的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02
c#實(shí)現(xiàn)隱藏與顯示任務(wù)欄的方法詳解
本篇文章是對(duì)c#中任務(wù)欄隱藏與顯示的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

