View Full Version : vb script to remove all printers?

31-01-2008, 09:25 AM
Does anyone know how to remove all network printers on logon? reason being there are a lot of non existent printers in users printers and faxes. There are scripts to remove individual printers but you have to know the exact name/path of the printer in order to delete it, is there some sort of wild card i can use to delete all printers so i can then map fresh ones?

at the moment the logon script for printers looks like this

On Error Resume Next
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\office\OfficeLaser"
WshNetwork.AddWindowsPrinterConnection "\\oa1\Photocopier-Admin"
WshNetwork.AddWindowsPrinterConnection "\\oa1\Photocopier-J"
WshNetwork.AddWindowsPrinterConnection "\\SWR01\SWRLaser"


31-01-2008, 10:29 AM
nevermind, i found one online and edited it to suit.
if anyone's interested here's the code to remove all network printers.

On error resume next

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo oPrinters.Item(i+1)
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)