Return to

Writing a .bat


Hey all,
I was wondering if anyone could help me with a little project my boss gave me.
He wants me to write a .bat file that will silently unmount and remount a network drive.
this is the example he gave me.
@echo off

net use * / delete /yes net use s: unc path /user: username password
but it doesn’t seem quiet right. which he has a history giving wrong information lol.
can anyone help me with this one?
thank you.



A little search brought up this:



Net use is the bat command you want to use both for mapping and unmapping. Here is a reference-

1 Like



Note last version technique as mapped drive is variable being declared then when unmapped being cleared from dim declaration

Dim =
'dim =

The spaces are significant. You created a variable named (enclosing single quotes added to show location of space) ‘location ’ with a value of ’ “bob”’.
If you want quotes in your value, then your code should look like
set location=“bob”
If you don’t want quotes, then your code should look like
set location=bob
Or better yet
set “location=bob”
The last syntax prevents inadvertent spaces from getting in the value, and also protects against special characters like & | etc.



Its better to use the direct IP instead of UNC path because sometimes PCs just dont show up in network discovery and so UNC breaks.



Another nice guide and note dotteddomainname aswell as /p:yes\no



Oh man thanks everyone for the replies.

My boss is a real dick and works me in to the ground so I’m sorry for the no response.