its_sam Posted April 15, 2014 Posted April 15, 2014 I have a very simple script to remove all network printers, however this does not remove old printers that are no longer attached to the network. How should I modify the attached script to remove 'all' printers? Go easy on me, scripts are not my forte remove-network-printers.vbs.txt
featured_spectre Posted April 15, 2014 Posted April 15, 2014 I've used this in the past to remove network printers 'Remove all Network printers but not local printers Set WshNetwork = WScript.CreateObject("WScript.Network") Set Printers = WshNetwork.EnumPrinterConnections For i = 0 to Printers.Count - 1 Step 2 If Left(ucase(Printers.Item(i+1)),2) = "\\" Then WScript.Echo Printers.Item(i+1) WSHNetwork.RemovePrinterConnection Printers.Item(i+1) End IF Next and this to remove local printers 'Remove all Local printers but not Network printers strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = FALSE") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next
its_sam Posted April 15, 2014 Author Posted April 15, 2014 Thanks for the reply. Whilst this does remove network printers, it does not seem to remove printers that are dead i.e status is "unable to connect" Any other ideas?
featured_spectre Posted April 15, 2014 Posted April 15, 2014 sorry, I missed that, this will do it. 'Remove all offline printers set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") set sInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where ExtendedPrinterStatus = 7") For Each sPrinter in sInstalledPrinters sPrinter.Delete_ Next
its_sam Posted April 15, 2014 Author Posted April 15, 2014 That didn't work either i'm afraid. Printers remain and doesn't return any form of error.
featured_spectre Posted April 15, 2014 Posted April 15, 2014 hmmm...that should detect all offline printers and remove them, networked or local...in that case, I am not sure where you can proceed from here.
its_sam Posted April 15, 2014 Author Posted April 15, 2014 Thanks for your suggestions. Looks like reg delete "hkcu\printers\connections" /f will work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now