All Forums >> [Scripting] >> Post a VBScript >> Remove Network Printers from Multiple Workstations Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
'Comments Section '------------------------------------------------------------------- 'VBS Multiple WS Network Printer Removal 'Created by Jim Martin 4:27 PM 8/24/2006 'Modified Microsoft Script to remove network printers 'Text file must be named machines.txt and located in script directory 'or the script will need to be edited '-------------------------------------------------------------------- 'End Comments On Error Resume Next Set WshNetwork = WScript.CreateObject("WScript.Network") set ofs = createobject("scripting.filesystemobject") set MachineList = ofs.opentextfile("machines.txt", 1, false) while not MachineList.atEndOfStream strComputer = MachineList.ReadLine() wscript.echo vbCrLf & "Connecting to " & strComputer & "..." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") if (Err.Number <> 0) then wscript.echo "Failed to connect to " & strComputer & "." On Error Resume Next else Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters 'Wscript.Echo "Name: " & objPrinter.Name 'Wscript.Echo "Location: " & objPrinter.Location if InStr(objPrinter.Name, "\\") > 0 then 'wscript.echo "Will delete: " & objPrinter.Name WshNetwork.RemovePrinterConnection objPrinter.Name End If Next End If Wend MachineList.close() Wscript.Echo "Finished removing network printers!"
I am quiet interested in your script to remove network printer connections for several workstations. My only delema is that I want to only remove 2 specific network printers. Each user here migh have several extra network printers in their "printers and faxes" list. I have searched for this info without any success. If you have an idea how, I would really appriciate it.