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.
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.
My idea is similar to dbenham's. Took me forever to figure out how to minimize the current console window though. I banged my head against the wall trying to get the
cmd
window not to ignore anAlt+Space
keypress usingWscript.Shell
's.SendKeys
method. Finally I turned to PowerShell to handle minimizing and restoring the working window.The advantage to this over dbenham's is that you'll inevitably have some rectal-cranially inverted user who gets bored with the running of your script and terminates it with the red X. dbenham's won't catch that, but mine should.
Sure, simply execute most of your script in a new CMD session:
As long as your console window remains open, the
net use /delete
command will always fire after the inner cmd session closes. It could close because of normal run, user presses Ctrl-C, or fatal error - the finalnet use \delete
will still fire.There is a very simple solution. Just write:
before your net use /delete command. The only way to break that command is to press ctrl+c. By example:
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.
I don't think this is possible. At the beginning of your script, you can use:
Or you could try
pushd
instead ofnet use
...This way, you will always have mapped drive correctly set.
You need to use traps to do this Traps