Batch file to change all network shares on computer

426 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

remap.bat

@ECHO OFF

IF "%1"=="" echo usage: remap oldserver newserver & goto :EOF
SETLOCAL ENABLEDELAYEDEXPANSION

for /f "tokens=2,3 delims= " %%a in ('net use ^| FIND /I "%1"') do (
   Set SHARE=%%b
   Set SHARE=!SHARE:%1=%2!
   net use /delete /y %%a
   net use /persistent:yes %%a !SHARE!
)

hope this helps, adopt the persistent:yes to your needs!