Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Delete network printers

1,015 views
Skip to first unread message

ThatsIT.net.au

unread,
Mar 7, 2008, 5:52:14 AM3/7/08
to

"gorahilly" <gora...@discussions.microsoft.com> wrote in message
news:69F4DEFC-D2B3-4F34...@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

Tom Lavedas

unread,
Mar 7, 2008, 8:06:39 AM3/7/08
to
On Mar 7, 5:52 am, "ThatsIT.net.au" <me@work> wrote:
> "gorahilly" <gorahi...@discussions.microsoft.com> wrote in message

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/

Corey Thomas - MCSE/MCSA/MCDBA

unread,
Mar 7, 2008, 5:15:00 PM3/7/08
to
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

0 new messages