Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

migrated from superuser.com Sep 12 '10 at 8:56

This question came from our site for computer enthusiasts and power users.

1  
What OS is this? –  JNK Sep 10 '10 at 16:54
    
Sorry, Mostly windows XP –  arkansasonline Sep 10 '10 at 16:55
    
You could a create a batch program to do this easily . If you plan to craete then you must ask this question in stackoverflow.com –  subanki Sep 10 '10 at 16:58
    
How many shares are we talking about? The effort to create a script needs to be balanced with the time it would take to do it the most efficient manual way :) –  JNK Sep 10 '10 at 17:00
1  
Are these PCs (and their users) in a Domain? –  Chris_K Sep 10 '10 at 17:04

4 Answers 4

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.

share|improve this answer
@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
share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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.