Win XP batch file / network drive map question

Tangent

[H]ard|Gawd
Joined
Jan 7, 2002
Messages
1,482
I'm trying to get a batch file to delete a network drive mapping and to remap to a different network share. The problem I'm having is that I can't get it to consistently delete the mapping, I have to browse to My Computer, right-click on the drive, and select disconnect from there to delete it. Is there a switch or other command I can use to force Windows to disconnect the network drive?
 
Here's what I've been using unsuccesfully:

net use h: /delete
net use h: \\server\share

The delete command just isn't succesful most of the time...
 
what about making the new mapped drive persistant? does that keep the old mapping from reoccuring?
 
If you're gonna be at the console when the file is run, just put a pause command between lines.

Code:
net use h: /delete
pause
net use h: \\server\share

Obviously you'd have to hit a key between commands, but it would ensure the first mapping is deleted.

Another way around this issue is to have two bat files. One would delete the mapped drive then call the second batch file that would map the second one.

I'm going to name the files map1.bat and map2.bat in this example:


map1.bat would look like:
Code:
net use h: /delete
call c:\map2.bat

map2.bat would look like:
Code:
net use h:\\server\share




These are both work arounds. I would imagine the bat file runs too quickly for the drive to be disconnected and reused.

Hope these help.
 
I'll try setting the newly mapped one to be persistent, hopefully that'll help. The problem is that the LAN admins here are cleaning up a horribly clutter active directory structure and group policies. I got put in a group that gets the h: drive mapped to a location that's not right for me only so I just wanted to be able to run a batch file to remap it to the right place, but even with the pause, for some reason the command prompt won't disconnect the drive...
 
Gambrinus said:
That syntax looks wrong - try "net use /delete h:" instead.
it doesn't matter:

C:\Documents and Settings\user>net use /?
The syntax of this command is:


NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]
 
try using pushd and popd. pushd \\server\sharename will assign it to Z: (or the next highest letter), while also changing to that drive. it can be used while in the command session, and popd will unmap it.
 
It's very strange that the net use h: /delete command isn't working for you 100% of the time. So even if you type this into the Run box it sometimes doesn't delete the mapping?
 
if the network assigned drives arent right for you, why not just remove all the drive mappings and remap what you need/want to have:>

Net Use * /D

Net Use H: \\Server\Share0
Net Use I: \\Server\Share1
Net Use J: \\Server\Share2
Net Use K: \\Server\Share3
 
How about testing the errorlevel variable to see if the command was successful? Example batch file:

Code:
@echo off

:delete
net use h: /delete
if errorlevel 1 goto delete

:map
net use h: \\server\share
if errorlevel 1 goto map

:success
echo Remapping of H: successfully completed.
 
F1xxer said:
It's very strange that the net use h: /delete command isn't working for you 100% of the time. So even if you type this into the Run box it sometimes doesn't delete the mapping?

Exactly

Transient, your went into an eternal loop. Even though nothing else was open or running it came back with an error that there was an active process using the device so it tried again, got the same error, etc... :p
 
Back
Top