1

I need to change all shares of //foo to //bar in a batch file. Say i have R: //foo/foo and Z: //foo/bar

I need to have a batch script that makes them R: //bar/foo and Z: //bar/bar

Anyone have any idea how to do this? I'm thinking of looping through somehow with net use but that's as far as I've come. Will be researching myself as well but thought I'd post here and see if somebody knew real quick as I'm in a bit of a crunch.

Thanks for you help.

This is for Windows XP Zachary

4 Answers4

2

I would use the follow in a batch file:

@echo off
REM Delete existing Mapped Drives
net use * /d Y

REM Map New Network Drive
net use R: \\bar\foo /persistent:yes
net use Z: \\bar\bar

echo Drives Mapped.

This can then be added to the users logon script path, provided the file is placed in the servers Netlogon folder.

EDIT

I have just re-read your question. Obviously my method is not practicle if you wish to change many shares. Could you advise if many shares are required to be changed?

Hope this helps, any questions let me know.

JamesK
  • 1,646
  • 11
  • 19
1
@echo off
REM delete the actual Network Drive
net use R: /DELETE
net use Z: /DELETE

REM Create the new Network Drive 
net use R: \\bar\foo
net use Z: \\bar\bar

If you want that network drive persist over reboot you need to add /persistent:yes to the net use command when you map the network driver, so for R:

net use R: \\bar\foo /persistent:yes
aleroot
  • 3,180
  • 6
  • 29
  • 37
0

Your best bet is probably a batch file using the FOR Command.

If you are able to get a list of the directories you want changed, you can feed that command an input file (like shares.txt) and it will iterate through each line. You can assign some fairly complex logic as described in the link.

Another option would be a VBScript but I think that would involve a bigger time investment, especially for something like this which doesn't require a great deal of analysis or logic.

JNK
  • 286
  • 2
  • 5
0

Net Use will change the drive mapping but not the underlying share as command runs on the client not the server.

There is no share rename, a new share can be added on the same folder and the old share can be deleted later once things are confirmed working. The catch is the new share requires new share permissions and if the path changes then new NTFS permissions may also need to be set.

RmtShare, http://ss64.com/nt/rmtshare.html, may work depending on the OS.
VBScript can also work well as it can do Share Permissions: MS Scripting Repository - Shared Folders. Link below, can't get hyperlink to work.

http://gallery.technet.microsoft.com/scriptcenter/en-us/site/search?f[0].Type=RootCategory&f[0].Value=storage&f[0].Text=Storage&f1.Type=SubCategory&f1.Value=sharedfolders&f1.Text=Shared%20Folders

Ed Fries
  • 1,619
  • 2
  • 12
  • 14