How can you remove network printers mapped by a vbscript from a terminal server/workstation?

I have a vbscript that used to map printers to all users in my domain. I have since moved away from this and am now using a third party app to manage printers. I need to be able to remove all the printers that were mapped using the script. I have tried a few different codes i found online (below) but they either do nothing at all (no errors, printers stay) or it errors out and says 'The network path cannot be found'. The print server these were mapped from is no longer in service, so these connections are no longer valid.
This is a sample of my code
Option Explicit 

 Sub AssignNetworkPrinters(default)

  Dim multiPrinter
  Dim objNetwork, strUser, objUser, group

  Set objNetwork = CreateObject("WScript.Network")
  strUser = objNetwork.UserName
  Set objUser = GetObject("WinNT://printserver/" & strUser)  
  Set multiPrinter = CreateObject("WScript.Network")
  multiPrinter.AddWindowsPrinterConnection "\\printserver\2055"
  multiPrinter.AddWindowsPrinterConnection "\\printserver\HPOff"
  multiPrinter.AddWindowsPrinterConnection "\\printserver\HPP1"
  multiPrinter.AddWindowsPrinterConnection "\\printserver\HPP16"
  multiPrinter.AddWindowsPrinterConnection "\\printserver\Xero"
 End Sub 'AssignNetworkPrinters()

 Sub Main()

  Dim default
  default = "."

  Call AssignNetworkPrinters(default)

 End Sub 'Main()


Call Main()

WScript.Quit

'End Script

Open in new window


I have tried using RemovePrinterConnection, and get 'The Network Path cannot be found'
 
Option Explicit 

 Sub AssignNetworkPrinters(default)

  Dim multiPrinter
  Dim objNetwork, strUser, objUser, group

  Set objNetwork = CreateObject("WScript.Network")
  strUser = objNetwork.UserName
  Set objUser = GetObject("WinNT://printserver/" & strUser)  
  Set multiPrinter = CreateObject("WScript.Network")
  multiPrinter.RemovePrinterConnection "\\printserver\2055"
  multiPrinter.RemovePrinterConnection "\\printserver\HPOff"
  multiPrinter.RemovePrinterConnection "\\printserver\HPP1"
  multiPrinter.RemovePrinterConnection "\\printserver\HPP16"
  multiPrinter.RemovePrinterConnection "\\printserver\Xero"
 End Sub 'AssignNetworkPrinters()

 Sub Main()
`
  Dim default
  default = "."

  Call AssignNetworkPrinters(default)

 End Sub 'Main()


Call Main()

WScript.Quit

'End Script

Open in new window


This code is supposed to remove all networked printers, but does absolutely nothing.
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections

For i = 0 to Printers.Count - 1 Step 2

    If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
        WScript.Echo Printers.Item(i+1)
        WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
    End IF
Next

Open in new window



I also tried this code, and it does nothing as well.
 
strComputer = "printserver"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

Open in new window



There are 6 Windows Terminal Servers that are affected, and over 100 PCs affected. Manually removing the printers from each PC would be a nightmare. If there is a way to remove ALL printers from the machine, i may give that a try - or remove ALL printers mapped from a specific server. Understand the mapped printers no longer exist, which may be why the script says 'The network path can not be found', but there is no way to bring the old print server back online with the shared printers - it's gone.

Thanks in advance.
LVL 1
mhdcommunicationsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Slav ZabickiSystem EngineerCommented:
do u have the printers listed in AD  DS?
 What version of 2003 do u have ? r2?
0
mhdcommunicationsAuthor Commented:
The printers are not listed in AD, and its Server 2003 SP2, not R2
0
Slav ZabickiSystem EngineerCommented:
create a logon script for the users or computers
try

Option Explicit

Dim objNetwork, objPrinters
Set objNetwork = CreateObject("WScript.Network")
Set objPrinters = objNetwork.EnumPrinterConnections


Dim sPrinterName
sPrinterName = "\\printserver\2055"
objNetwork.RemovePrinterConnection sPrinterName, True, True

sPrinterName = "\\printserver\HPOff"
objNetwork.RemovePrinterConnection sPrinterName, True, True

sPrinterName = "\\printserver\HPP1"
objNetwork.RemovePrinterConnection sPrinterName, True, True

sPrinterName = "\\printserver\HPP16"
objNetwork.RemovePrinterConnection sPrinterName, True, True

sPrinterName = "\\printserver\Xero"
objNetwork.RemovePrinterConnection sPrinterName, True, True
 
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
Slav ZabickiSystem EngineerCommented:
or a hardcore version

create a batch

reg delete "hkcu\printers\connections" /f

deploy in AD
0
mhdcommunicationsAuthor Commented:
Both solutions worked, the one from zabicki is what i ended up going with.
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
Operating Systems

From novice to tech pro — start learning today.