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?

link|improve this question

75% accept rate
feedback

2 Answers

up vote 3 down vote accepted

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
link|improve this answer
Consider adding /persistent:yes to the end of this net use command to make the drive mapping persistent across reboots. – jftuga Jan 14 '11 at 3:07
feedback

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 exists w:nul goto END
net use w: \\webserver\share /persistent:yes

:END
@echo continue on with batch file here
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.