Networked drive in purgatory after `net use` start-up script

Jeff picture Jeff · May 6, 2011 · Viewed 10.7k times · Source

I have a BAT file that runs on startup via the group policy on an internal server. The BAT executes a nant script which then maps several external locations via net use command. Until now, all mappings have been to external computers that are part of a different domain via public IPs.

net use e: \\111.111.111.111\someshare$ /persistent:yes
net use f: \\111.111.111.222\someshare$ /persistent:yes
net use g: \\111.111.111.333\someshare$ /persistent:yes

This has been successful. Now, I added a new computer that is part of the same network and domain as the internal server. While the old mappings continue to work, the new mapping does not.

net use h: \\anothercomputer\d$\somefolder /persistent:yes

I only know that this doesn't work because subsequent scripts that depend on this drive mapping are all failing, saying that the location doesn't exist. If I try to run the same connection script manually, net use says

System error 85 has occurred... The local device name is already in use.

Ok, so it mapped already somewhere, somehow. So I try to unmap it using net use h: /d and that fails.

The network connection could not be found.

So I cannot map it. I cannot unmap it. Apparently it exists in some networking purgatory. What is going on here? How can I get this new location mapped and visible to my scripts?

Answer

wimh picture wimh · May 15, 2011

First check if drive h: was mapped using a different account. When a drive is mapped from a service, it is only available from the system account, and there is also a different running it normally, or using the UAC "Run as administrator" feature. If you want to unmap it, you must do it the same way as it was mapped.

You can check if you can ping the other computer before trying to map a drive.

You can also try to connect to the other computer using an explicit username and password. And if you map it in a login script, there is no need to use the /persistent option.

net use \\anothercomputer /user:username password > c:\temp\netuse.log 2>&1
net use h: \\anothercomputer\d$\somefolder 

In the example above I write the output of the first net use command to a logfile, so you can check for errormessages afterwards.

If you use the /persistent option, you should not need to remap it again, you can use

if exist h:\nul ...

to check if drive h: already exists.