Delete Unused Printer Ports

Deletes any printer ports that have been installed on a computer but are not in use.

 
 
 
 
 
1 Star
(1)
Add to favorites
Printing
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Script error when 2 printer on the same TCP/IP Port !
    1 Posts | Last post January 23, 2013
    • Hi,
      
      I have the case of 2 printers on the same Tcp/ip Port (PS and PCL6) and i have an error with this delete port script at this point :
      
      For Each objPrinter in colPrinters
          objDictionary.Add objPrinter.PortName, objPrinter.PortName
      Next
      
      Because there will be 2 same entries keys that block the dictionary.
      
      So I have make this change :
      
      For Each objPrinter in colPrinters
          if objDictionary.Exists(objPrinter.PortName) then
          else
          objDictionary.Add objPrinter.PortName, objPrinter.PortName
          end if
      Next
      
      => Tell me if you like it ... Thanks !
  • Use this if not working for you (Access Denied errors)
    1 Posts | Last post December 16, 2010
    • if you are getting Access Denied errors when trying to run this script then add the following line after the "Set objWMIService = GetObject........." line
      
      objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"
      
      i.e.
      
      ************************************************************
      Set objDictionary = CreateObject("Scripting.Dictionary")
      
      strComputer = "."
      
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      
      objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege"
      
      
      Set colPrinters =  objWMIService.ExecQuery _
          ("Select * from Win32_Printer")
      
      For Each objPrinter in colPrinters 
          objDictionary.Add objPrinter.PortName, objPrinter.PortName
      Next
      
      Set colPorts = objWMIService.ExecQuery _
          ("Select * from Win32_TCPIPPrinterPort")
      
      For Each objPort in colPorts
          If objDictionary.Exists(objPort.Name) Then
          Else
              ObjPort.Delete_
          End If
      Next
      ************************************************************
      
      
      I'd like to credit where I found this after a lot of searching:
      http://www.petri.co.il/forums/showthread.php?t=50755