Best trick 2 avoid control-break(Terminate batch job) prompt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Best trick 2 avoid control-break(Terminate batch job) prompt

#1 Post by MKANET » 22 Apr 2012 19:22

I know that there's no way to intercept the control-c/control-break key sequence in the Windows command interpreter. However, there are some ways to avoid this.

It's very easy for me to avoid this completely if I only have a simple command; which I execute via start /B /WAIT.

However, the problem is I have a relatively complex/big batch file which calls out to other dependent batch files very frequently.

I tried to make a starter.cmd batch file which executes my main batch file using start /B /WAIT, however, this doesnt seem to protect against nested batch files. I see weird things happen... such as, seeing the command prompt, then continuing back to the batch file.

The only other trick I know is remapping keys via ansi.sys; however, that's not feasible since I don't have the option to modify config.NT.

I am open to using 3rd party utilities; as long as they are extremely small and discrete.

Thanks in advance, you guys are really amazing!

EDIT: I even tried remapping keys using the registry. Unfortunately, this method requires logging off or rebooting; which isn't feasible in this case.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#2 Post by aGerman » 23 Apr 2012 12:41

I don't understand why you use START /WAIT instead of CALL.

If you have to START another Batch file for whatever reason you need to run CMD /C and pass the file name as parameter. E.g.

Code: Select all

start "" /b /wait cmd /c "yourfile.bat"

Regards
aGerman

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#3 Post by MKANET » 23 Apr 2012 14:50

Hi aGerman, unfortunately that didn't make any difference. My ultimate goal is finding a way to prevent the "terminate batch job (Y/N)" prompt from the simplest way possible. It seems that since my original main batch file that makes several calls out to different child batch files complicates things.

I'm open to any other methods such as keyboard key remapping as well.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#4 Post by foxidrive » 23 Apr 2012 15:49

MKANET wrote:I'm open to any other methods such as keyboard key remapping as well.


Electric cattle prods for those people who are trying to stop the batch from running, assuming it is a legit batch.

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#5 Post by MKANET » 23 Apr 2012 16:09

LOL!!

foxidrive wrote:
MKANET wrote:I'm open to any other methods such as keyboard key remapping as well.


Electric cattle prods for those people who are trying to stop the batch from running, assuming it is a legit batch.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#6 Post by aGerman » 23 Apr 2012 16:15

foxidrive wrote:Electric cattle prods for those people who are trying to stop the batch from running, assuming it is a legit batch.

*rofl* :lol:

@MKANET
I assume there is no way.
I also don't understand why. Neither you could disable the X button nor you could protect the cmd process from terminating via taskmanager. What's the sense of that exercise?

Regards
aGerman

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#7 Post by Ed Dyreen » 23 Apr 2012 17:16

'
You can disable the x button using

Code: Select all

cmdow.EXE @ /DIS
Since

Code: Select all

BREAK=OFF
isn't supported on anything newer than win98, I do not know how to disable the CTRL+C easily using batch code only.

But it would be easier to prevent the batch from showing up at all

Code: Select all

cmdow.EXE /RUN /HID "process"

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#8 Post by MKANET » 23 Apr 2012 17:36

Hi Ed, my batch file is interactive. CMDOW /DIS disables the entire dos console window

Edit: Just go to be clear, I'm trying to prevent the "Terminate batch job (Y/N)" prompt. I'm not trying to disable the Window from closing.


Ed Dyreen wrote:'
You can disable the x button using

Code: Select all

cmdow.EXE @ /DIS
Since

Code: Select all

BREAK=OFF
isn't supported on anything newer than win98, I do not know how to disable the CTRL+C easily using batch code only.

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#9 Post by MKANET » 24 Apr 2012 08:32

While looking for a solution I found the quote below :)

I am a very strong supporter of P.E.T.A. (People for Ethical Treatment of Algorithms) and believe that any code, no matter how long it takes (or in my case how badly written it is), must be allowed the dignity to complete.

http://www.databison.com/index.php/prev ... execution/


foxidrive wrote:Electric cattle prods for those people who are trying to stop the batch from running, assuming it is a legit batch.

Shaun
Posts: 1
Joined: 04 May 2012 00:29

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#10 Post by Shaun » 04 May 2012 00:57

Hello MKANET, I too had the same problem as my Dell laptop doesn't have the Ctrl Break key. Well, after a Google research, I found a software, AutoHotKey that can remap your keyboard. Its a good one. You can get it here: http://www.autohotkey.com/download/. Or else if the Ctrl Break key's absence is your only problem that you can simply download and execute this file :http://www.4shared.com/file/rxRy6865/Right_Alt__CtrlBreak.html. This very file makes your Right Alt key to behave as the Ctrl Break key. Hope this solves your problem. :D

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#11 Post by foxidrive » 04 May 2012 01:16

I think he wants to disable it, not have a key to do it.

To disable it requires a hexedit of cmd.exe - there is info on the net for that.

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#12 Post by MKANET » 04 May 2012 10:43

Yeah, that's one way to do it; but, not really that great of an idea since there's more than one version of cmd.exe

I was hoping if there wasn't a good way to do this natively, to at least find a 3rd party command line executable which suppresses the control key (or control-break) via API. Unfortunately, I didn't find anything like that via good. I can remap the control key via registry; however, the changes don't take effect until the user logs off or reboots.
foxidrive wrote:I think he wants to disable it, not have a key to do it.

To disable it requires a hexedit of cmd.exe - there is info on the net for that.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#13 Post by foxidrive » 04 May 2012 17:44

MKANET wrote:Yeah, that's one way to do it; but, not really that great of an idea since there's more than one version of cmd.exe


The trouble with your question is that you haven't got any mention of OS in the first post.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#14 Post by Squashman » 23 Oct 2015 09:00

Why doesn't Control-C kill a batch file when it is using xcopy for input?

OperatorGK
Posts: 66
Joined: 13 Jan 2015 06:55

Re: Best trick 2 avoid control-break(Terminate batch job) pr

#15 Post by OperatorGK » 23 Oct 2015 10:01

Squashman wrote:Why doesn't Control-C kill a batch file when it is using xcopy for input?

How you can use XCOPY for keyboard input? Never known that.

Post Reply