Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

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
share|improve this answer
    
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. –  another_netadmin Jul 20 '10 at 20:42
    
The printers have to have a network path.... Just use that path instead of mine. Should work. –  Campo Jul 21 '10 at 16:22

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?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.