2016-04-19 1 views
1

オプションの一覧が掲載されているコードを実行しようとしていますが、操作の該当する番号を押すとコマンドが実行され、その後に実行するコマンドが再度尋ねられます。私は次のコードを書いていますが、実行するだけでプログラムは終了します。それを継続してループにするにはどうすればいいですか?コマンドプロンプトでバッチファイルにコマンドを追加するにはどうすればよいですか?

@echo off 

echo 1)System information 
echo 2)Ping 
echo 3)IP configuration 
echo 4)Verify Drivers 
echo 5)Driver List 
set /p num= Type the corresponding number to perform an operation: 
if %num%==1 (
systeminfo 
) 
if %num%==2 (
ping www.google.com 
) 
if %num%==3 (
ipconfig /all 
) 
if %num%==4 (
verifier 
) 
if %num%==5 (
driverquery 
) 
pause 

助けてください。前もって感謝します。あなたの最後の行で

答えて

0

あなたは私が入れて、この方法のように、スタートif '%choice%'=='y' goto start

@echo off 
:start 
Cls 
color 1A 
echo 1)System information 
echo 2)Ping 
echo 3)IP configuration 
echo 4)Verify Drivers 
echo 5)Driver List 
echo 6)Get Serial Number 
set /p num= Type the corresponding number to perform an operation: 
if %num%==1 (
cls 
systeminfo 
) 
if %num%==2 (
cls 
ping www.google.com 
) 
if %num%==3 (
cls 
ipconfig /all 
) 
if %num%==4 (
cls 
verifier 
) 
if %num%==5 (
cls 
driverquery 
) 
if %num%==6 (
cls 
wmic bios get serialnumber 
) 
set /p choice="Do you want to restart? Press 'y' and enter for Yes: " 
if '%choice%'=='y' goto :start 

:省略しかしdynamic menuhttp://www.dostips.com

説明から:

この簡単なメニューフレームワークは、特定の 署名のバッチラベルを解析し、それらをメニューアイテムとしてリストします。自己解析機能により、 メニューが汎用化されます。メニューのインフラストラクチャを変更せずに新しい 機能ブロックを追加することで、新しいメニュー項目を挿入できます。

@echo off 
Title Dynamic Menu 
:menuLOOP 
Color 1A & Mode con cols=55 lines=15 
echo(
echo( ====================Menu==================== 
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do (
echo  %%A %%B) 
echo(
echo( ============================================ 
set choice= 
echo(& set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF 
echo(& call :menu_[%choice%] 
GOTO:menuLOOP 
::************************* 
:menu_[1] System Information 
cls & color B 
Mode con cols=120 lines=70 
echo(
systeminfo 
echo Hit any key to return to the main menu... 
pause>nul 
Goto:menuLOOP 
::************************* 
:menu_[2] Ping 
cls & color B 
Mode con cols=90 lines=15 
echo(
ping www.google.com 
echo Hit any key to return to the main menu... 
pause>nul 
Goto:menuLOOP 
::************************* 
:menu_[3] IP configuration 
cls & color B 
Mode con cols=100 lines=60 
echo(
ipconfig /all 
echo Hit any key to return to the main menu... 
pause>nul 
Goto:menuLOOP 
::************************* 
:menu_[4] Verify Drivers 
cls & color B 
Mode con cols=90 lines=15 
echo(
verifier 
echo Hit any key to return to the main menu... 
pause>nul 
Goto:menuLOOP 
::************************* 
:menu_[5] Driver List 
cls & color B 
Mode con cols=90 lines=90 
echo(
driverquery 
echo Hit any key to return to the main menu... 
pause>nul 
Goto:menuLOOP 
::************************* 
:menu_[6] Bios serial Number 
cls & color B 
Mode con cols=50 lines=15 
echo(
wmic bios get serialnumber 
echo Hit any key to return to the main menu... 
pause>nul 
Goto:menuLOOP 
::************************ 

あなたはまた、少し簡単なものかもしれない、私は自分自身を試してみましたが、私は次のことを得ることができたthis example with a dynamic menu : DJ Batch Music Player

0

を見てとることができ、この1のあなたの考えは何ですか?

:start 
cls 
color 1A 
@echo off 
echo 1)System information 
echo 2)Ping 
echo 3)IP configuration 
echo 4)Verify Drivers 
echo 5)Driver List 
echo 6)Get Serial Number 
set /p num= Type the corresponding number to perform an operation: 
if %num%==1 (
cls 
systeminfo 
) 
if %num%==2 (
cls 
ping www.google.com 
) 
if %num%==3 (
cls 
ipconfig /all 
) 
if %num%==4 (
cls 
verifier 
) 
if %num%==5 (
cls 
driverquery 
) 
if %num%==6 (
cls 
wmic bios get serialnumber 
) 
set /p choice="Do you want to restart? Press 'y' and enter for Yes: " 
if '%choice%'=='y' goto start 

これは別の方法です。私はヒットとトライアルの方法でそれを得た。

+1

はい、 'goto'は行く方法です。 [choice](http://ss64.com/nt/choice.html)コマンドにも興味があります。 – Stephan

関連する問題