zoukankan      html  css  js  c++  java
  • C#程序及批处理中确定windows操作系统的方法

    先上一段代码:

     private void Form1_Load(object sender, EventArgs e)
            {
                OperatingSystem os = Environment.OSVersion;
                switch (os.Platform)
                {
                    case PlatformID.Win32Windows:
                        switch (os.Version.Minor)
                        {
                            case 0:
                                label1.Text = "Windows   95 ";
                                break;
                            case 10:
                                if (os.Version.Revision.ToString() == "2222A ")
                                    label1.Text = "Windows   98   第二版 ";
                                else
                                    label1.Text = "Windows   98 ";
                                break;
                            case 90:
                                label1.Text = "Windows   Me ";
                                break;
                        }
                        break;
                    case PlatformID.Win32NT:
                        switch (os.Version.Major)
                        {
                            case 3:
                                label1.Text = "Windows   NT   3.51 ";
                                break;
                            case 4:
                                label1.Text = "Windows   NT   4.0 ";
                                break;
                            case 5:
                                switch (os.Version.Minor)
                                {
                                    case 0:
                                        label1.Text = "Windows   200 ";
                                        break;
                                    case 1:
                                        label1.Text = "Windows   XP ";
                                        break;
                                    case 2:
                                        label1.Text = "Windows   2003 ";
                                        break;
                                }
                                break;
                            case 6:
                                switch (os.Version.Minor)
                                {
                                    case 0:
                                        label1.Text = "Windows  Vista ";
                                        break;
                                    case 1:
                                        label1.Text = "Windows   7 ";
                                        break;
                                }
                                break;
                        }
                        break;
                }
            }

    这段代码很明显地揭示了Windows系列操作系统的版本编号。那么,使用一下批处理即可达到相同目的:

    @echo off
    ver|find "5.1"
    if errorlevel 1 goto check7
    if errorlevel 0 goto winxp
    :winxp
    echo windowsxp
    rem 这行注释请改成命令z
    goto end
    
    :check7
    ver|find "6.1"
    if errorlevel 1 goto other
    if errorlevel 0 goto win7
    :win7
    echo win7
    rem 这行注释请改成命令x
    goto end
    
    :other
    echo otherwindows
    :end
    pause

    注:以上代码均来自于网络。

  • 相关阅读:
    攻防世界web新手区前六关
    JS-数组基础知识3
    CSRF攻击的原理和spring security对CSRF攻击的解决方法
    Java开发微信公众号
    内部类
    Java Web整合开发(30) -- Spring的ORM模块
    win10安装mysql
    jquery 事件冒泡的介绍以及如何阻止事件冒泡
    jquery中attr和prop的区别介绍
    jQuery 层次选择器
  • 原文地址:https://www.cnblogs.com/pzy4447/p/3655333.html
Copyright © 2011-2022 走看看