在批处理文件菜单 [英] Menus in Batch File

查看:295
本文介绍了在批处理文件菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常不创建批处理文件,因为我只需要输入什么,我需要到运行对话框或命令提示符下,但我试图做一个只是为了让我获得基本工具在Windows和检查的事情(我真的不需要它,但我觉得我爸爸会发现它有用)。我所熟悉的(但新)与Python,所以如果使用python这些东西是一个更好的选择,我能做到这一点,但是我觉得一批在做这样简单的东西的最佳方式。问题是我的菜单。我想是因为我的菜单中,它是通过所有的命令做选择的命令之前骑自行车。任何帮助,这将是完全AP preciated,批处理脚本是低于code框。

  ECHO OFF
:菜单
回声这是一个简单的清理和修复工具。请选择一个选项:
回声1 - 检查硬盘C:\\错误和inconsistancies。
回音2 - 更新IP地址
回声3 - 查看IP地址信息
回声4 - 通过ping http://www.google.co.uk/检查互联网连接
回声5 - 启动磁盘清理实用工具
回声6 - 平192.168.0.1
回声7 - 平192.168.1.1
回声8 - 打开记事本
选择/ N / C:12345678 / M选择一个选项(1-8)
IF ERRORLEVEL == 1 GOTO CHKDSK
IF ERRORLEVEL == 2 GOTO清零
IF ERRORLEVEL == 3 GOTO DISPLAYIP
IF ERRORLEVEL == 4 GOTO PINGGOOGLE
IF ERRORLEVEL == 5 GOTO CLEANMGR
IF ERRORLEVEL == 6 GOTO PING0
IF ERRORLEVEL == 7 GOTO萍
IF ERRORLEVEL == 8 GOTO STARTNOTE
:CHKDSK
CHKDSK C:
暂停
转到菜单
:更新
使用ipconfig / renew
暂停
转到菜单
:DISPLAYIP
IPCONFIG / ALL
暂停
转到菜单
:PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
暂停
转到菜单
:CLEANMGR
CLEANMGR
暂停
转到菜单
:PING0
PING 192.168.0.1
暂停
转到菜单
:萍
PING 192.168.1.1
暂停
转到菜单
:STARTNOTE
启动记事本
暂停
转到菜单


解决方案

您可如果不这样做的测试的ERRORLEVEL的价值可言,而只是使用它使用一个更简单的方法的组装与多个目的地转到命令。为了使此方法有效,必须改变标签,使他们包括ERRORLEVEL值。

  ECHO OFF
:菜单
回声这是一个简单的清理和修复工具。请选择一个选项:
回声1 - 检查硬盘C:\\错误和inconsistancies。
回音2 - 更新IP地址
回声3 - 查看IP地址信息
回声4 - 通过ping http://www.google.co.uk/检查互联网连接
回声5 - 启动磁盘清理实用工具
回声6 - 平192.168.0.1
回声7 - 平192.168.1.1
回声8 - 打开记事本
选择/ N / C:12345678 / M选择一个选项(1-8)
GOTO LABEL-%ERRORLEVEL%:LABEL-1 CHKDSK
CHKDSK C:
暂停
转到菜单
:LABEL-2清零
使用ipconfig / renew
暂停
转到菜单
:LABEL-3 DISPLAYIP
IPCONFIG / ALL
暂停
转到菜单
:LABEL-4 PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
暂停
转到菜单
:LABEL-5 CLEANMGR
CLEANMGR
暂停
转到菜单
:LABEL-6 PING0
PING 192.168.0.1
暂停
转到菜单
:LABEL-7平1
PING 192.168.1.1
暂停
转到菜单
:LABEL-8 STARTNOTE
启动记事本
暂停
转到菜单

I don't usually create batch files as I just type what I need into the run box or the command prompt but I'm trying to make one just to let me access basic utilities in windows and check up on things (I really don't need it but I think my dad would find it helpful). I am familiar (but new) with python so if using python for these things is a better option I can do that, however I thought batch was the best way of doing something as simple as this. The problem is with my menu. I think because of my menu , it is cycling through all of the commands before doing the command selected. Any help with this will be fully appreciated, the batch script is in a code box below.

echo off
:menu
echo This is a simple cleanup and repair utility. Please select an option:
echo 1 - Check the hard disk c:\ for errors and inconsistancies. 
echo 2 - Renew the IP address 
echo 3 - View IP Address information
echo 4 - Check internet connection  by pinging http://www.google.co.uk/
echo 5 - Start disk cleanup utility
echo 6 - ping 192.168.0.1
echo 7 - ping 192.168.1.1
echo 8 - Open notepad
choice /n /c:12345678 /M "Choose an option (1-8) "
IF ERRORLEVEL == 1 GOTO CHKDSK
IF ERRORLEVEL == 2 GOTO RENEW
IF ERRORLEVEL == 3 GOTO DISPLAYIP
IF ERRORLEVEL == 4 GOTO PINGGOOGLE
IF ERRORLEVEL == 5 GOTO CLEANMGR
IF ERRORLEVEL == 6 GOTO PING0
IF ERRORLEVEL == 7 GOTO PING1
IF ERRORLEVEL == 8 GOTO STARTNOTE
:CHKDSK
CHKDSK C:
PAUSE
goto menu
:RENEW
IPCONFIG /RENEW
PAUSE
goto menu
:DISPLAYIP
IPCONFIG /ALL
PAUSE
goto menu
:PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
PAUSE
goto menu
:CLEANMGR
CLEANMGR
PAUSE
goto menu
:PING0
PING 192.168.0.1
PAUSE
goto menu
:PING1
PING 192.168.1.1
PAUSE
goto menu
:STARTNOTE
START NOTEPAD
PAUSE
goto menu

解决方案

You may use a much simpler approach if you don't test the errorlevel value at all, but just use it to assemble a goto command with multiple destinations. In order for this method to work, the labels must be changed so they include the errorlevel values.

echo off
:menu
echo This is a simple cleanup and repair utility. Please select an option:
echo 1 - Check the hard disk c:\ for errors and inconsistancies. 
echo 2 - Renew the IP address 
echo 3 - View IP Address information
echo 4 - Check internet connection  by pinging http://www.google.co.uk/
echo 5 - Start disk cleanup utility
echo 6 - ping 192.168.0.1
echo 7 - ping 192.168.1.1
echo 8 - Open notepad
choice /n /c:12345678 /M "Choose an option (1-8) "
GOTO LABEL-%ERRORLEVEL%

:LABEL-1 CHKDSK
CHKDSK C:
PAUSE
goto menu
:LABEL-2 RENEW
IPCONFIG /RENEW
PAUSE
goto menu
:LABEL-3 DISPLAYIP
IPCONFIG /ALL
PAUSE
goto menu
:LABEL-4 PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
PAUSE
goto menu
:LABEL-5 CLEANMGR
CLEANMGR
PAUSE
goto menu
:LABEL-6 PING0
PING 192.168.0.1
PAUSE
goto menu
:LABEL-7 PING1
PING 192.168.1.1
PAUSE
goto menu
:LABEL-8 STARTNOTE
START NOTEPAD
PAUSE
goto menu

这篇关于在批处理文件菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆