2

I'm using the following script to handle removing any old networked printers from machines and then assigning the propper ones and making one of them the default. This script is assigned to the OU the workstations reside in and uses group policy loopback so all users that login will get the appropriate printers mapped for them.

I tried to use the new Printer Manager as part of W2K3 R2 but when assigning the default this way I get an error that the printer doesn't exist so I'm back to using the script.

One flaw that I'm noticing is that it won't remove any printers that happen to be mapped from an RDP session (we don't see this everywhere but there are a few locations). Is there any way to enumerate all RDP printers and remove them similar to how I'm enumerating and removing networked printers?

' 
' Printers.vbs - Windows Logon Script.
'

RemovePrinters
AddPrinters

Sub RemovePrinters()
   On Error Resume Next
   Dim strPrinter
   Set objNetwork = WScript.CreateObject("WScript.Network")
   Set colPrinters = objNetwork.EnumPrinterConnections
   For i = 0 to colPrinters.Count -1 Step 2
      strPrinter=CStr(colPrinters.Item(i+1))
      If Not InStr(strPrinter,"\\") = 0 Then
         objNetwork.RemovePrinterConnection strPrinter, True, True
      End If
   Next
End Sub


Sub AddPrinters()
   On Error GoTo 0
   Set objNetwork = CreateObject("WScript.Network") 
   objNetwork.AddWindowsPrinterConnection "\\printers1\JH120-DELL5310"
   objNetwork.SetDefaultPrinter "\\printers1\Jh120-DELL5310"
End Sub

2 Answers 2

0

I use this to remove printers seems to work in all scenarios.

    Dim objNetwork, objPrinters
Set objNetwork = CreateObject("WScript.Network")
Set objPrinters = objNetwork.EnumPrinterConnections
' ### Delete selected network printer
objNetwork.RemovePrinterConnection "\\GARCIA\Dell Printer 3100cn PS", True, True
objNetwork.RemovePrinterConnection "\\HENDRIX\Dell Printer 3100cn PS", True, True
objNetwork.RemovePrinterConnection "\\HENDRIX\Brother PCL5e Driver", True, True
objNetwork.RemovePrinterConnection "\\HENDRIX\HP LaserJet 4250 PS", True, True
objNetwork.RemovePrinterConnection "\\STANLEY\HP LaserJet 4250 PS", True, True
2
  • Not working for me. The paths aren't \\servername\printer-share-name. I can enumerate them from the WScript.Network class and display them by getting rid of the If statement in the code about but they just come up as something like: HP Printer on oldprintsrv (from aworkstation) When running RemovePrinterConnection to that name nothing happens. Jul 20, 2010 at 20:42
  • The printers have to have a network path.... Just use that path instead of mine. Should work.
    – Campo
    Jul 21, 2010 at 16:22
0

I'm not sure how the OS handles RDP printers, whether it treats them as "local" printers or "network" printers. If the printers show up in the registry under HKLM\System\CurrentControlSet\Control\Print\Printers, then use printui.dll to delete the printer object like this:

rundll32 printui.dll,PrintUIEntry /dl /n "PRINTER NAME GOES HERE"

OTOH, if the printers show up in the registry under HKCU\Printers\Connections, then the method you're using should have done the trick. Maybe there's something else preventing the connections from being deleted? Are the users connected to a terminal server when the script runs?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .