map to drive on server with bat file

1

I have a web server that I want to map a drive to it. I want to do this in a .bat file. Pseudo ->

Check if a drive at an ip address has been mapped to a local drive. If it has then progress with a reference to the drive If not map to a local drive and then progress with a reference to the drive

Is this possible and if so how can I achieve it?

Niall Collins

Posted 2011-01-14T00:12:27.837

Reputation: 323

Answers

4

You do not need to check if a mapping exists if the same drive letter is always used, the net use command will simply fail if it is unsuccessful at remapping with a system error 85.

e.g:

net use x: \\10.1.2.3\Share

John T

Posted 2011-01-14T00:12:27.837

Reputation: 149 037

Consider adding /persistent:yes to the end of this net use command to make the drive mapping persistent across reboots. – jftuga – 2011-01-14T03:07:59.500

0

You can see if the drive mapping exists, say w: by checking for the nul device on that drive. I would also suggest using server name in the net use command instead of as IP address.

if exist w:nul goto END
net use w: \\webserver\share /persistent:yes

:END
@echo continue on with batch file here

jftuga

Posted 2011-01-14T00:12:27.837

Reputation: 2 877

if exist, not if exists – Michael S. – 2013-11-25T13:27:15.680