Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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
share|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

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
share|improve this answer
    
if exist, not if exists –  gentlesea Nov 25 '13 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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