batch script if user press Ctrl+C do a command before exiting
问题 I wrote a script which is doing net use at the beginning and net use /DELETE at the end. But if user decides to press Ctrl + C and exits the script, I need to do a net use /DELETE . Is that possible? I can't find anything on google. 回答1: Sure, simply execute most of your script in a new CMD session: @echo off if "%~1" neq "_start_" ( net use ... cmd /c "%~f0" _start_ %* net use /delete ... exit /b ) shift /1 REM rest of script goes here As long as your console window remains open, the net use