Yes simply use a if statment to test
set objNetwork = CreateObject("wscript.network")
Set objPrinters = objNetwork.EnumPrinterConnections
For i = 0 to objPrinters.Count - 1 Step 2
PrinterPath = objPrinters.Item(i+1)
if PrinterPath = \\prntsrvr1\printer1 then
objNetwork.RemovePrinterConnection PrinterPath, true, true
end if
Next
If there are multiple printers supported by a single print server as
implied by the OPs question, I think this slightly altered approach
that searches the PrinterPath might serve better (plus, there are a
couple of missing quotes in the example code above) ...
if Instr(lcase(PrinterPath), "prntsrvr1") > 0 then
objNetwork.RemovePrinterConnection PrinterPath, true, true
end if
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Here's a simple way to disconnect a specific printer:
Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
WshNetwork.RemovePrinterConnection PrinterPath, true, true
You can wrap this into a sub and pass the printer if you like. This is good
if you know the name of the printer you want to disconnect. In your case,
you want to disconnect ALL printers. To do that, first get the collection
of printers by using EnumPrinterConnections. Then iterate through each
printer and disconnect it using the method above. If you need help, let me
know!
-Corey Thomas
MCSE/MCSA/MCDBA