Monday, August 8, 2011

Removing a printer with VBScript

I also had to remove the old copier/printers as part of the upgrade. Here is VBScript to remove all printers that have '7th' in their name. Modify to suit your needs.

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

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer where Name Like '%7th%'")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next


Resource: http://www.cruto.com/resources/vbscript/vbscript-examples/printing/client/Delete-a-Printer.asp

No comments:

Post a Comment