Page 1 of 2

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

Posted: 22 Apr 2012 19:22
by MKANET
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.

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

Posted: 23 Apr 2012 12:41
by aGerman
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

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

Posted: 23 Apr 2012 14:50
by MKANET
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.

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

Posted: 23 Apr 2012 15:49
by foxidrive
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.

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

Posted: 23 Apr 2012 16:09
by MKANET
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.

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

Posted: 23 Apr 2012 16:15
by aGerman
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

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

Posted: 23 Apr 2012 17:16
by Ed Dyreen
'
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"

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

Posted: 23 Apr 2012 17:36
by MKANET
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.

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

Posted: 24 Apr 2012 08:32
by MKANET
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.

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

Posted: 04 May 2012 00:57
by Shaun
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

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

Posted: 04 May 2012 01:16
by foxidrive
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.

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

Posted: 04 May 2012 10:43
by MKANET
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.

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

Posted: 04 May 2012 17:44
by foxidrive
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.

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

Posted: 23 Oct 2015 09:00
by Squashman
Why doesn't Control-C kill a batch file when it is using xcopy for input?

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

Posted: 23 Oct 2015 10:01
by OperatorGK
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.