script – How to disable CTRL+C in batch?

Question:

Is it possible to disable the CTRL+C command in batch?

Answer:

Another option would be a script like the one below, adapt it to your needs:

This batch file cannot be canceled by Ctrl-C and if canceled by Ctrl-Break the cmd.exe window will close.

@echo off
setlocal

if "%~1" equ "NonCancelable" goto NonCancelable
start "" /B cmd /C "%~F0" NonCancelable
exit

:NonCancelable
echo You can NOT cancel me!
echo/
set "var="
set /P "var=Enter password (enter Exit to end): "
if /I "%var%" neq "exit" goto :NonCancelable
echo Terminating non cancelable...
pause
exit

Original: https://stackoverflow.com/a/36953316/935330

Scroll to Top
AllEscort