vbs script is not executed

I have a vbs script which deletes printers and maps the new one from different server
When I run it on my computer it was working. But when I tried on a user PC computers there is a problem and nothing has happen. The script does not report any errors. But the settings that need to be changed with this script doesn't change.
I need an urgent  help because the server1 has failed and I need to redirect the users to another print server
PCs are windowsXP SP3


strOldServer = "server1"
strNewServer = "server2"

strComputer = "."
Set WSHNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer")

strOldServer = prepServer(strOldServer)
strNewServer = prepServer(strNewServer)

For Each objPrinter in colInstalledPrinters
   strName = objPrinter.Name
   iPrinterLocation = InStr(UCase(objPrinter.Name),UCase(strOldServer))
   If iPrinterLocation > 0 then
      strPrinter = strNewServer & Right(strName, Len(strName) - Len(strOldServer))
      objPrinter.Delete_
      WSHNetwork.AddWindowsPrinterConnection strPrinter
      If objPrinter.Default = True Then
         WSHNetwork.SetDefaultPrinter strPrinter
      End If
   End If
Next


Function prepServer(strServer)
   If Left(strServer, 2) <> "\\" then
      strServer = "\\" & strServer
   End If
   If Right(strServer, 1) <> "\" then
      strServer = strServer & "\"
   End If
   prepServer = strServer
End Function

Open in new window

dedriAsked:
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.

Ken ButtersCommented:
Try running this modified version so you can see what is going on :

It won't do anything, but at least you can see what it's trying to do, and that will help you figure it out.

strOldServer = "server1"
strNewServer = "server2"

strComputer = "."
Set WSHNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer")

strOldServer = prepServer(strOldServer)
strNewServer = prepServer(strNewServer)
Wscript.echo "Count from InstalledPrinters:" & colInstalledPrinters.count 
For Each objPrinter in colInstalledPrinters
   strName = objPrinter.Name
   Wscript.echo "checking if " & objPrinter.name & " is in " & strOldServer
   iPrinterLocation = InStr(UCase(objPrinter.Name),UCase(strOldServer))
   
   If iPrinterLocation > 0 then
      strPrinter = strNewServer & Right(strName, Len(strName) - Len(strOldServer))
      Wscript.Echo "Deleting :" & objPrinter.Delete_
      Wscript.Echo "Adding :" & WSHNetwork.AddWindowsPrinterConnection  & strPrinter
      If objPrinter.Default = True Then
         Wscript.Echo "Setting Default : " & WSHNetwork.SetDefaultPrinter & strPrinter
      End If
   End If
Next


Function prepServer(strServer)
   If Left(strServer, 2) <> "\\" then
      strServer = "\\" & strServer
   End If
   If Right(strServer, 1) <> "\" then
      strServer = strServer & "\"
   End If
   prepServer = strServer
   Wscript.Echo "prepServer=" & prepServer
End Function

Open in new window

0

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
dedriAuthor Commented:
On a problem computers I had to fix it manually. I don't see any problem on all other computers. So I was not able to test your modified script with echo messages
0
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.