国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

使用 Visual C# .NET 檢查 Windows 版本

2024-07-10 13:00:16
字體:
供稿:網(wǎng)友
  • 網(wǎng)站運(yùn)營(yíng)seo文章大全
  • 提供全面的站長(zhǎng)運(yùn)營(yíng)經(jīng)驗(yàn)及seo技術(shù)!
  • 感謝jackyoung02(冷雨夜)!!!!




    如何:使用 visual c# .net 檢查 windows 版本 (q304283)

    --------------------------------------------------------------------------------

    本文討論的內(nèi)容屬于:
    microsoft visual c# .net (2002)

    --------------------------------------------------------------------------------

    如果您想要參考 microsoft visual basic .net 版本的文章,請(qǐng)參考q304289。

    如果您想要參考 microsoft visual c++ .net 版本的文章,請(qǐng)參考q307394。

    本文內(nèi)容:

    概述
    需求
    獲取 windows 版本數(shù)據(jù)
    獲取 windows 系統(tǒng)信息
    判斷平臺(tái)
    判斷 windows 95, windows 98, windows 98 第二版或 windows me 的版本
    判斷 windows nt, windows 2000, 或 windows xp 的版本
    編譯樣例

    --------------------------------------------------------------------------------

    概述
    本文描述了如何檢查您的應(yīng)用運(yùn)行于哪個(gè)操作系統(tǒng)上。本文區(qū)分了 microsoft windows 95, microsoft windows 98, microsoft windows 98 第二版, microsoft windows millennium edition (windows me), microsoft windows nt 3.51, microsoft windows nt 4.0, microsoft windows 2000, 和 microsoft windows xp。

    返回
    --------------------------------------------------------------------------------

    需求
    microsoft visual c# .net
    對(duì) visual c# 編程有一定理解
    返回
    --------------------------------------------------------------------------------

    獲取 windows 版本數(shù)據(jù)
    為了檢查操作系統(tǒng),您必須獲取下列數(shù)據(jù):

    +--------------------------------------------------------------+
    | |windows|windows|windows|windows nt|windows|windows|
    | | 95 | 98 | me | 4.0 | 2000 | xp |
    +--------------------------------------------------------------+
    |platformid | 1 | 1 | 1 | 2 | 2 | 2 |
    +--------------------------------------------------------------+
    |主版本號(hào) | 4 | 4 | 4 | 4 | 5 | 5 |
    +--------------------------------------------------------------+
    |副版本號(hào) | 0 | 10 | 90 | 0 | 0 | 1 |
    +--------------------------------------------------------------+

    注釋:盡管本文的代碼在所有 32-bit 版本的 windows 上驗(yàn)證過,但 windows 95 和 windows nt 3.51 不支持 microsoft visual studio .net 或者 common language runtime。

    返回
    --------------------------------------------------------------------------------

    獲取 windows 系統(tǒng)信息
    在 system 命名空間中包含了一個(gè)名為 operatingsystem 的類。在 operatingsystem 類中的屬性提供了正在使用的操作系統(tǒng)信息。system.environment 類中的 osversion 屬性返回一個(gè) operatingsystem 對(duì)象。

    system.operatingsystem osinfo = system.environment.osversion;

    返回
    --------------------------------------------------------------------------------

    判斷平臺(tái)
    判斷操作系統(tǒng)的第一步就是辨別正在使用的是哪個(gè)操作系統(tǒng)。您可以使用 operatingsystem 類中的 platformid 屬性來決定在用的是哪個(gè)操作系統(tǒng)。

    例如,枚舉類型屬性 win32windows 的值指明了下列操作系統(tǒng)之一:

    windows 95
    windows 98
    windows 98 second edition
    windows me
    類似的,winnt 屬性的值指明了下列操作系統(tǒng)之一:

    windows nt 3.51
    windows nt 4.0
    windows 2000
    windows xp
    switch(osinfo.platform)
    {
    case system.platformid.win32windows:
    {
    // code to determine specific version of windows 95,
    // windows 98, windows 98 second edition, or windows me.
    }

    case system.platformid.win32nt:
    {
    // code to determine specific version of windows nt 3.51,
    // windows nt 4.0, windows 2000, or windows xp.
    }

    }

    返回
    --------------------------------------------------------------------------------

    判斷 windows 95, windows 98, windows 98 第二版或 windows me 的版本
    如果您想判斷 windows 95, windows 98, windows 98 第二版或 windows me 的版本,您可以分析主版本號(hào)和副版本號(hào)。

    // platform is windows 95, windows 98, windows 98 second edition,
    // or windows me.
    case system.platformid.win32windows:

    switch (osinfo.version.minor)
    {
    case 0:
    console.writeline ("windows 95");
    break;
    case 10:
    if(osinfo.version.revision.tostring()=="2222a")
    console.writeline("windows 98 second edition");
    else
    console.writeline("windows 98");
    break;
    case 90:
    console.writeline("windows me");
    break;
    }break;

    返回
    --------------------------------------------------------------------------------

    判斷 windows nt, windows 2000, 或 windows xp 的版本
    如果您想判斷 windows nt, windows 2000, 或 windows xp 的版本,您也可以分析主版本號(hào)和副版本號(hào)。

    // platform is windows nt 3.51, windows nt 4.0, windows 2000,
    // or windows xp.
    case system.platformid.win32nt:

    switch(osinfo.version.major)
    {
    case 3:
    console.writeline("windows nt 3.51");
    break;
    case 4:
    console.writeline("windows nt 4.0");
    break;
    case 5:
    if (osinfo.version.minor==0)
    console.writeline("windows 2000");
    else
    console.writeline("windows xp");
    break;
    }break;

    返回
    --------------------------------------------------------------------------------

    編譯樣例
    下一步就是編譯一個(gè)項(xiàng)目來測(cè)試功能:

    在 visual studio .net 中,打開一個(gè)新的 c# console 應(yīng)用。系統(tǒng)會(huì)默認(rèn)打開 class1.cs 的代碼窗口。
    用下面的代碼替換所有 class1.cs 中的代碼:?
    using system;

    namespace determineos_cs
    {
    class class1
    {
    static void main(string[] args)
    {
    // get operatingsystem information from the system namespace.
    system.operatingsystem osinfo =system.environment.osversion;

    // determine the platform.
    switch(osinfo.platform)
    {
    // platform is windows 95, windows 98,
    // windows 98 second edition, or windows me.
    case system.platformid.win32windows:

    switch (osinfo.version.minor)
    {
    case 0:
    console.writeline ("windows 95");
    break;
    case 10:
    if(osinfo.version.revision.tostring()=="2222a")
    console.writeline("windows 98 second edition");
    else
    console.writeline("windows 98");
    break;
    case 90:
    console.writeline("windows me");
    break;
    }
    break;

    // platform is windows nt 3.51, windows nt 4.0, windows 2000,
    // or windows xp.
    case system.platformid.win32nt:

    switch(osinfo.version.major)

    {
    case 3:
    console.writeline("windows nt 3.51");
    break;
    case 4:
    console.writeline("windows nt 4.0");
    break;
    case 5:
    if (osinfo.version.minor==0)
    console.writeline("windows 2000");
    else
    console.writeline("windows xp");
    break;
    }break;
    }
    console.readline ();
    }
    }
    }



    發(fā)表評(píng)論 共有條評(píng)論
    用戶名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 嘉禾县| 顺义区| 张北县| 凤城市| 商城县| 克东县| 湖州市| 同仁县| 静宁县| 泸定县| 松阳县| 淮北市| 牡丹江市| 聊城市| 泾阳县| 玛沁县| 尉犁县| 清涧县| 垦利县| 筠连县| 乌鲁木齐市| 武宣县| 黄平县| 松溪县| 九江县| 新民市| 博客| 东安县| 丹阳市| 商水县| 揭西县| 罗城| 朝阳区| 康定县| 临桂县| 宽城| 湖北省| 区。| 海伦市| 广德县| 彭水|