Problem:

When migrating a print driver or moving to another print server you would like to delete existing connections to the printer.

Solution:

Create a Log-on or Logoff script to remove the printer connections based on print server or based on Print driver:

Based on driver:

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colInstalledPrinters =  objWMIService.ExecQuery _
    (“Select * from Win32_Printer Where DriverName = ‘Printdriver'”)

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

Where ‘Printdriver’ is the name of the print driver when looking at the Print server properties.

Based on print server:

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colInstalledPrinters =  objWMIService.ExecQuery _
    (“Select * from Win32_Printer Where ServerName like ‘Printserver'”)

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

Where ‘Printserver’ is the name of the old print server.

Links:

Posted in: Group Policy, Microsoft, Printer, Windows 2008, Windows 2008 R2, Windows 7