Getting a VB Script error: An Attempt was made to remember a device that had previously been remembered.

I am still getting error, Can anyone help me with this script. I seem to be so close.  I have been struggling with this for awhile. This is a startup script not a logon script.  I use a computer policy to start the script. Unless someone else has better script.  But I need to remove the map first if there is one then map it to where it needs to be. Reason why I need this, is I have tellers that sign onto there teller software at there branch and need map drive that points to that branches server. If I setup a Logon script all is fine, but the problem comes in when all my tellers move around from branch to branch their login script would be pointing at the wrong branch server. So I figured a Startup script would be better. I would create a computer policy that would be specific to each branch. All I would then have to do is put ther computer into that container with that policy. So no matter who signs onto that computer it will be mapped to the correct server. Please I need some help with this. Our Teller turn over rate is high so, I would rather not have to go setup map drive for each user profile on every machine. Hope this makes sense.

I have SP4 installed.

Line 31
Char 1
Error: An Attempt was made to remember a device that had previously been remembered.
Code: 800704B2
Source: wshNetwork.mapnetworkdrive

Here is the script code that I have running at startup.

**************************
Option Explicit


Dim objNetwork
Dim DriveLetter1, RemotePath1
Dim AllDrives, AlreadyConnected, Network1,i

Set Network1 = CreateObject("WScript.Network")
DriveLetter1 = "T:" ' This letter must be in CAPITALS.

RemotePath1 = "\\farnam-tlrsrvr\Teller"

Set objNetwork = CreateObject("WScript.Network")
Set AllDrives = objNetwork.EnumNetworkDrives()


AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2
If AllDrives.Item(i) = DriveLetter1 Then AlreadyConnected = True
Next

If AlreadyConnected = True then
objNetwork.RemoveNetworkDrive DriveLetter1
objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

Else

objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

End if

WScript.Quit
' End of Script
SplunkerAsked:
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.

anil_uCommented:
Change the following line
objNetwork.RemoveNetworkDrive DriveLetter1
to
objNetwork.RemoveNetworkDrive DriveLetter1, true, true
SplunkerAuthor Commented:
Yeah, I found that suggestion also. I tried it earlier. I tried it again just to make sure. Still the same error.
anil_uCommented:
Ok try this


Option Explicit


Dim objNetwork, WshShell
Dim DriveLetter1, RemotePath1, Command
Dim AllDrives, AlreadyConnected, Network1,i

Set Network1 = CreateObject("WScript.Network")
DriveLetter1 = "T:" ' This letter must be in CAPITALS.

RemotePath1 = "\\farnam-tlrsrvr\Teller"

Set objNetwork = CreateObject("WScript.Network")
Set AllDrives = objNetwork.EnumNetworkDrives()


AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2

If AllDrives.Item(i) = DriveLetter1 Then
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Command = "net use " & DriveLetter1 & " /delete /yes"
  WshShell.Run(Command), 7, True
  Set WshShell = nothing
 
Next

objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

WScript.Quit
' End of Script

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
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

SplunkerAuthor Commented:
Now I get error:

Line: 26
Char: 1
Error Unexpected 'Next'
Code: 800A041F
Source: Microsoft VBscript compilation error
SplunkerAuthor Commented:
Well I figured out the unexpected "next" error. But now I am back to the original error.  Heres how I fixed the last code.

Option Explicit


Dim objNetwork, WshShell
Dim DriveLetter1, RemotePath1, Command
Dim AllDrives, AlreadyConnected, Network1,i

Set Network1 = CreateObject("WScript.Network")
DriveLetter1 = "T:" ' This letter must be in CAPITALS.

RemotePath1 = "\\farnam-tlrsrvr\Teller"

Set objNetwork = CreateObject("WScript.Network")
Set AllDrives = objNetwork.EnumNetworkDrives()


AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2

If AllDrives.Item(i) = DriveLetter1 Then
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Command = "net use " & DriveLetter1 & " /delete /yes"
  WshShell.Run(Command), 7, True
  Set WshShell = nothing

END IF

NEXT  

objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

WScript.Quit
' End of Script
anil_uCommented:
Sorry bout that I did not test it.
Ok, the next thing to try would be to see if the "IF" statement is working

After the following line
For i = 0 To AllDrives.Count - 1 Step 2
type
wscript.echo  AllDrives.Item(i)

This will then output the drive letters
You would have to run this from the command prompt
start->run->cmd-> cd to script folder->cscript nameOfScript.vbs

If you do not see the T drive, change the IF statement to
For i = 0 To AllDrives.Count - 1


SplunkerAuthor Commented:
I am wondering now if its OS related. I have windows 2000 on my machine... the one I am testing with and I am getting these errors. I put another computer with XP into the same container with the group policy to run this script and it worked fine. No errors. Worked with my original script and the new one that you came up with. I am wondering whats up with my machine.
anil_uCommented:
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
Windows 2000

From novice to tech pro — start learning today.