Break out of script and goto menu

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Break out of script and goto menu

#1 Post by falcios » 05 Jun 2021 08:57

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.

ShadowThief
Expert
Posts: 1029
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Break out of script and goto menu

#2 Post by ShadowThief » 05 Jun 2021 11:11

Yes.

ShadowThief
Expert
Posts: 1029
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Break out of script and goto menu

#3 Post by ShadowThief » 05 Jun 2021 11:16

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.

falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Re: Break out of script and goto menu

#4 Post by falcios » 05 Jun 2021 12:01

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?

falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Re: Break out of script and goto menu

#5 Post by falcios » 13 Jun 2021 16:47

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 :DISCONNECT
if %input% == 1 goto :IPCONFIG
if %input% == 2 goto :STATS
echo.
:DISCONNECT
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

ShadowThief
Expert
Posts: 1029
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Break out of script and goto menu

#6 Post by ShadowThief » 13 Jun 2021 18:19

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.

falcios
Posts: 41
Joined: 02 Mar 2017 05:38

Re: Break out of script and goto menu

#7 Post by falcios » 14 Jun 2021 05:36

Thanks ShadowThief for your response.

I hope someone has the answer.

Post Reply