Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a local printer with VBScript

Status
Not open for further replies.

ZenKenobi

MIS
Aug 4, 2004
3
US
Does anyone know how to delete a local printer using VBScript. There are plenty of resources out there that describe deleting a network printer connection, but nothing on deleting a local printer. I tried this

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'Symantec Fax Starter Edition'")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete
Next
(Code written by MBouchard - gotta give credit where credit is due)
But when I get to objPrinter.delete, I get a runtime error (Object doesn't support property or method). This was run on a Win2K box. Can anyone help?

Thanks,
ZenKenobi
 
Hello ZenKenobi,

Win32_printer does not have a delete method. So I do not know how .delete function with your source of info.

Also, would the RemovePrinterConnection method of wscript.network do? Check it out from vbs documentation.

regards - tsuji
 
I've tried the RemovePrinterConnection method, but it seems to only work for Network printers. When I enum printer connections, it only displays network printer connections. I tried the RemovePrinterConnection method using the UNC name of the printer as an argument (\\ComputerName\PrinterName) and still no dice. Surely Win32_printer has some kind of method that can remove a device. Thank you very much for all your help.

ZenKenobi

"I'd rather have a bottle in front of me than a frontal lobotomy." - Tom Waits
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top