I am using the script to delete all network printers installed on a
workstation.
Is there a way to specify to delete on the printers on a specific printer
server?
For example:
\\prntsrvr1\printer1
\\prntsrvr2\printer2

Is there a way to say delete all printers pointing to prntsrvr2?

Re: Delete network printers by ThatsIT

ThatsIT
Fri Mar 07 04:52:14 CST 2008


"gorahilly" <gorahilly@discussions.microsoft.com> wrote in message
news:69F4DEFC-D2B3-4F34-8F92-F42EC0190420@microsoft.com...
>I am using the script to delete all network printers installed on a
> workstation.
> Is there a way to specify to delete on the printers on a specific printer
> server?
> For example:
> \\prntsrvr1\printer1
> \\prntsrvr2\printer2
>
> Is there a way to say delete all printers pointing to prntsrvr2?

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


Re: Delete network printers by Tom

Tom
Fri Mar 07 07:06:39 CST 2008

On Mar 7, 5:52 am, "ThatsIT.net.au" <me@work> wrote:
> "gorahilly" <gorahi...@discussions.microsoft.com> wrote in message
>
> news:69F4DEFC-D2B3-4F34-8F92-F42EC0190420@microsoft.com...
>
> >I am using the script to delete all network printers installed on a
> > workstation.
> > Is there a way to specify to delete on the printers on a specific printer
> > server?
> > For example:
> > \\prntsrvr1\printer1
> > \\prntsrvr2\printer2
>
> > Is there a way to say delete all printers pointing to prntsrvr2?
>
> 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/

RE: Delete network printers by CoreyThomasMCSEMCSAMCDBA

CoreyThomasMCSEMCSAMCDBA
Fri Mar 07 16:15:00 CST 2008

Hi,

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

"gorahilly" wrote:

> I am using the script to delete all network printers installed on a
> workstation.
> Is there a way to specify to delete on the printers on a specific printer
> server?
> For example:
> \\prntsrvr1\printer1
> \\prntsrvr2\printer2
>
> Is there a way to say delete all printers pointing to prntsrvr2?