Is it possible to break out of a batch file while it is running and have it return to the :Menu in the script?
Thanks in advance.
Break out of script and goto menu
Moderator: DosItHelp
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Break out of script and goto menu
Because of how simple this question appears, I'm worried that when I say "use goto menu," you're going to respond with "that didn't work."
If you can elaborate on what you mean by "break out of a batch file" and "while it's running," (how would a batch file do things when it wasn't running?) I can give you a more complete answer.
If you can elaborate on what you mean by "break out of a batch file" and "while it's running," (how would a batch file do things when it wasn't running?) I can give you a more complete answer.
Re: Break out of script and goto menu
Thanks for your reply.
Towards the top of the batch file i have the :MENU label. When the script is running and it is stopped by CTRL break, I want it to go to the :MENU label.
How can this be done?
Towards the top of the batch file i have the :MENU label. When the script is running and it is stopped by CTRL break, I want it to go to the :MENU label.
How can this be done?
Re: Break out of script and goto menu
Here is a sample of my batch file below.
When I do CTRL + Break, I get the message terminate batch job {Y/N)
If I select N, I want the batch file to return to the :MENU label.
Is there a way I can do this?
Thanks in advance.
@echo off
:MENU
Echo Press 0 for DISCONNECT
Echo Press 1 for IPCONFIG
Echo Press 2 for STATS
set /p input=Enter 0-2:
if %input% == 0 goto ISCONNECT
if %input% == 1 goto :IPCONFIG
if %input% == 2 goto :STATS
echo.
ISCONNECT
cls
net use * /delete /y
pause
cls
GOTO :MENU
:IPCONFIG
cls
echo.
ipconfig /release
pause
ipconfig /renew
pause
cls
GOTO :MENU
:STATS
cls
net stats work
pause
cls
GOTO :MENU
When I do CTRL + Break, I get the message terminate batch job {Y/N)
If I select N, I want the batch file to return to the :MENU label.
Is there a way I can do this?
Thanks in advance.
@echo off
:MENU
Echo Press 0 for DISCONNECT
Echo Press 1 for IPCONFIG
Echo Press 2 for STATS
set /p input=Enter 0-2:
if %input% == 0 goto ISCONNECT
if %input% == 1 goto :IPCONFIG
if %input% == 2 goto :STATS
echo.
ISCONNECT
cls
net use * /delete /y
pause
cls
GOTO :MENU
:IPCONFIG
cls
echo.
ipconfig /release
pause
ipconfig /renew
pause
cls
GOTO :MENU
:STATS
cls
net stats work
pause
cls
GOTO :MENU
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Break out of script and goto menu
Somebody more qualified than I am will have to answer that, but my gut instinct is that since the CTRL+Break is processed by cmd.exe itself and not the script, the script has no idea you've pressed CTRL+Break or responded to it, so there is no way it can even look for that.
Re: Break out of script and goto menu
Thanks ShadowThief for your response.
I hope someone has the answer.
I hope someone has the answer.