新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → 使用 Visual C# .NET 检查 Windows 版本 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2065 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 使用 Visual C# .NET 检查 Windows 版本 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     admin 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      头衔:W3China站长
      等级:计算机硕士学位(管理员)
      文章:5255
      积分:18406
      门派:W3CHINA.ORG
      注册:2003/10/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给admin发送一个短消息 把admin加入好友 查看admin的个人资料 搜索admin在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给admin  访问admin的主页 引用回复这个贴子 回复这个贴子 查看admin的博客楼主
    发贴心情 使用 Visual C# .NET 检查 Windows 版本


    发信人: minerva (cheng), 信区: DotNET
    标  题: 使用 Visual C# .NET 检查 Windows 版本  
    发信站: BBS 水木清华站 (Sun Sep 28 18:57:11 2003), 转信

    如何:使用 Visual C# .NET 检查 Windows 版本 (Q304283)
    ----------------------------------------------------------------------------
    ----
    本文讨论的内容属于:
    Microsoft Visual C# .NET (2002)
    ----------------------------------------------------------------------------
    ----
    如果您想要参考 Microsoft Visual Basic .NET 版本的文章,请参考Q304289。
    如果您想要参考 Microsoft Visual C++ .NET 版本的文章,请参考Q307394。
    本文内容:
    概述
    需求
    获取 Windows 版本数据
    获取 Windows 系统信息
    判断平台
    判断 Windows 95, Windows 98, Windows 98 第二版或 Windows Me 的版本
    判断 Windows NT, Windows 2000, 或 Windows XP 的版本
    编译样例
    ----------------------------------------------------------------------------
    ----
    概述
    本文描述了如何检查您的应用运行于哪个操作系统上。本文区分了 Microsoft Windows
    95, Microsoft Windows 98, Microsoft Windows 98 第二版, Microsoft Windows Mi
    llennium Edition (Windows Me), Microsoft Windows NT 3.51, Microsoft Windows  
    NT 4.0, Microsoft Windows 2000, 和 Microsoft Windows XP。
    返回
    ----------------------------------------------------------------------------
    ----
    需求
    Microsoft Visual C# .NET
    对 Visual C# 编程有一定理解
    返回
    ----------------------------------------------------------------------------
    ----
    获取 Windows 版本数据
    为了检查操作系统,您必须获取下列数据:
    +--------------------------------------------------------------+
    |           |Windows|Windows|Windows|Windows NT|Windows|Windows|
    |           |  95   |  98   |  Me   |    4.0   | 2000  |  XP   |
    +--------------------------------------------------------------+
    |PlatformID | 1     | 1     | 1     | 2        | 2     | 2     |
    +--------------------------------------------------------------+
    |主版本号     | 4     | 4     | 4     | 4        | 5     | 5     |
    +--------------------------------------------------------------+
    |副版本号     | 0     | 10    | 90    | 0        | 0     | 1     |
    +--------------------------------------------------------------+
    注释:尽管本文的代码在所有 32-bit 版本的 Windows 上验证过,但 Windows 95 和  
    Windows NT 3.51 不支持 Microsoft Visual Studio .NET 或者 common language run
    time。
    返回
    ----------------------------------------------------------------------------
    ----
    获取 Windows 系统信息
    在 System 命名空间中包含了一个名为 OperatingSystem 的类。在 OperatingSystem  
    类中的属性提供了正在使用的操作系统信息。System.Environment 类中的 OSVersion  
    属性返回一个 OperatingSystem 对象。
        System.OperatingSystem osInfo = System.Environment.OSVersion;
    返回
    ----------------------------------------------------------------------------
    ----
    判断平台
    判断操作系统的第一步就是辨别正在使用的是哪个操作系统。您可以使用 OperatingSy
    stem 类中的 PlatformID 属性来决定在用的是哪个操作系统。
    例如,枚举类型属性 Win32Windows 的值指明了下列操作系统之一:
    Windows 95
    Windows 98
    Windows 98 Second Edition
    Windows Me
    类似的,WinNT 属性的值指明了下列操作系统之一:
    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 的版本,
    您可以分析主版本号和副版本号。
        // 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 的版本,您也可以分析主版
    本号和副版本号。
        // 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;
    返回
    ----------------------------------------------------------------------------
    ----
    编译样例
    下一步就是编译一个项目来测试功能:
    在 Visual Studio .NET 中,打开一个新的 C# console 应用。系统会默认打开 Class
    1.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 ();
          }
       }
    }

    --

    ※ 来源:·BBS 水木清华站 smth.org·[FROM: 210.42.97.154]
    上一篇
    返回上一页
    回到目录
    回到页首


       收藏   分享  
    顶(0)
      




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

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

    第十二章第一节《用ROR创建面向资源的服务》
    第十二章第二节《用Restlet创建面向资源的服务》
    第三章《REST式服务有什么不同》
    InfoQ SOA首席编辑胡键评《RESTful Web Services中文版》
    [InfoQ文章]解答有关REST的十点疑惑

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/11/9 2:25:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给Google AdSense  访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/3 4:53:40

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms