Re- map Windows Network Drive using a script

Need to re-map all the windows network drives by any script which works in windows.

Below is the example which shows existing network drive maps and what it should be re-mapped to
Before re-map

"net use" command on windows command prompt

 Y:        \\xyz\SAMPLE\LOGIN


After re-map

"net use" command on windows command prompt

 F:        \\change1\SAMPLE1\LOGIN
 Y:        \\change2\SAMPLE2\LOGIN

what ever windows network drives exist with net use command, we need to re-map without
i)deleting or
ii)disconnecting the drive.

If re-map fails for any reason the script should just exist without doing nothing(disconnecting or deleting existing drive mapping)
Which means at any time existing drive mapping should be saved with the exception of re-map is successful.

Its very urgent and any help with this would be really great.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I use kixtart. free and plenty of examples.
pal2kAuthor Commented:
do we need to install something or it is default in windows

I dont have option of installing anything. I have to do with windows dos scripting / wscript or vb script
Fred MarshallPrincipalCommented:
I'm not sure about your specification.  For example:

\\server1\folder1\folder2 is mapped to F:

Now map:
\\server1\folder1\folder2 to G:

Then disconnect:
\\server1\folder1\folder2 is mapped from F:

How is this not a "disconnect" even though it affects a change in the mapping?

How about:

net use E: \\server1\folder1\folder1....
REM OK so now it's mapped to E: and now we want to change it:
net use F: \\server1\folder1\folder1....
REM Now it's mapped twice
net use E: /delete
REM Now it's no longer mapped to E: and it's still mapped to F: voila!  a change has occured while maintaining a connection.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

pal2kAuthor Commented:
what i mean is to re-map without removing the drive map
pal2kAuthor Commented:
Again whai I mean is if the re-map is not successful , the current existing drive map should not e disturbed
Neil RussellTechnical Development LeadCommented:
What you mean is

delete the current map
Try and map new share to same drive
if it fails remap the old one back.

Fred MarshallPrincipalCommented:
OK.  Thanks.

Then an IF statement in the batch file would appear to be in order:

IF something then action1 else action2

So, "something" would be a test for if the drive letter exists.  If it exists then action1 can be to delete the prior map.  If not then no action so action2 can be just not there at all.

Sorry I don't have time right now to write the script.  I hope this works.
Bill PrewCommented:
See if this is any help, you might not want all the logging, but for testing it's probably useful.  I think it does what you asked.

@echo off
setlocal EnableDelayedExpansion

REM Define new mappings needed
set New_F:=\\change1\SAMPLE1\LOGIN
set New_Y:=\\change2\SAMPLE2\LOGIN

REM Define filename to log activity to
set LogFile=c:\ee\ee27497777.txt

REM Delete logfile if it exists
if exist "%LogFile%" del "%LogFile%"

echo %DATE% %TIME% - %~nx0 Started on computer [%COMPUTERNAME%].>>"%LogFile%"

REM Loop through all current defined mapped drives
REM Inside loop %%A will be the drive letter, %%B will be the sharename it is mapped to
for /F "skip=2 tokens=2,3 delims=," %%A in ('wmic netuse get remotepath^,localname^,status /format:csv') do (

  REM Log a message about remapping this share
  echo ***** Checking drive [%%A] current share [%%~B] *****

  if defined New_%%A (
    if /I "!New_%%A!" NEQ "%%~B" (
      echo ***** Remapping drive [%%A] from [%%~B] to [!New_%%A!] *****

      REM Save current mapping
      set Old_%%A=%%~B

      REM First, delete the existing mapping for this drive
      net use %%A /DELETE /Y

      REM Then remap using the new drive and sharename
      net use %%A "!New_%%A!" /PERSISTENT:YES || (
        echo ***** Error remapping drive [%%A], restoring to [%%~B] *****
        net use %%A "!Old_%%A!" /PERSISTENT:YES


echo %DATE% %TIME% - %~nx0 Finished on computer [%COMPUTERNAME%].>>"%LogFile%"

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.