batch script if user press Ctrl+C do a command before exiting

后端 未结 5 811
闹比i
闹比i 2020-12-19 07:43

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 +

5条回答
  •  眼角桃花
    2020-12-19 08:05

    There is a very simple solution. Just write:

    ping -l www."site".com -t 65500>nul
    

    before your net use /delete command. The only way to break that command is to press ctrl+c. By example:

    net use "arguments"
    ping -l www.google.com -t 65500>nul
    net use /delete
    

    This is a good way to detect ctrl+c, but beware of the site address you write, because it risks to make that site crash. You should, by consequence, write the address of an unusual site, or of a site of your own(Attention: the site must be existing), like a blog or something like that.

提交回复
热议问题