Saturday, October 4, 2008

RemovePrinters.vbs

This script enumerates the unc mapped printers for the logged on user on a Windows XP system and remove the printers.
removeprinters.vbs:
Set WshNetwork = WScript.CreateObject(”WScript.Network”)
Set oPrinters = WshNetwork.EnumPrinterConnections
For enumi = 0 to oPrinters.Count - 1 Step 2
WScript.Echo “Port ” & oPrinters.Item(enumi) & ” = ” & oPrinters.Item(enumi+1)
if left(oPrinters.Item(enumi+1),2) = “\\” then
WshNetwork.RemovePrinterConnection oPrinters.Item(enumi+1), true, true
end if
Next