Discussion Locked

restore remapped drive

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there a way use a batch file or script to take a mapped drive (ie net use f: \\serverA\share), remap it for an application that needs that drive (ie net use f: /del then net use f: \\serverB\share), and then remap the drive back to the original unc share after the application is done?

7 replies

by woody h

I have done this before. Create a batch file that would look like the following:
@echo off
net use F: /delete
net use F: \\serverB\share
application.exe
net use F: /delete
net use F: \\serverA\share

Create a shortcut to the batch file and place it on the users desktop to allow them to use it. Hope this helps.

Woody

by shanghai sam

Thanks, but the problem is that we have different users who are mapped to different shares for the same drive letter. So I need a way to "remember" the original mapped share so it can be restored after the application is finished using the remapped drive letter.
Sorry if I didn't explain this well enough.

by mckaytech

There are a couple ways you could do this. Probably the easiest would be to use the Set command to write the existing mapping to an environment variable then after the application closed, you could restore the original mapping from that variable. If the drives are mapped by a logon script, you could put the Set command there and your batch file would then just have the line "net use f: %oldshare%".

If I offer one hint from my experience, however, in the long run it has caused far less problems to just define drive mappings by application for all the users. For example, within my organization, the O drive is mapped to the Oracle server. If the user doesn't need Oracle access, they just don't have an O drive mapped. In all cases, the users HomeDir is mapped to their K drive and so on.

There is a political and training cost to this if your users have been accustomed to choosing their own drive letters, but in the long run, it REALLY simplifies network management and troubleshooting.

paul

by beermonster

Shell scripting, my favourite !!! This requires NT4 or greater.

I take it you know the drive letter before hand, we'll say its F:

net use | find /I "F:" > C:\temp.txt

that line pipes the details of the F: mapping to a file, note the single > overwrites the files previous contents. now delete and map your new drive. When you are ready to remap,

for /F "tokens=3" %%A in (c:\temp.txt) do net use F: %%A

Note thats all on one line of course. : )

This discussion is closed to new replies.