Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Need Help With Script To List and Delete Printers

Reply
 
Old 04-14-2009   #1 (permalink)
Christopher Beard


 
 

Need Help With Script To List and Delete Printers

We are migrating from one print server to another and the printers from the
old print server still exist on the client PCs and I want to delete them.
What I am trying to do is write a script to do the following on the client
PCs:
1. List the user's printers
2. Pipe that list into an array
3. Search the array for printers starting with \\OLDPRINTSERVER
4. Delete those printers
I know how to list printers and delete printers, can someone help with the
rest? Thank you in advance!
Christopher

My System SpecsSystem Spec
Old 04-14-2009   #2 (permalink)
Alex K. Angelopoulos


 
 

Re: Need Help With Script To List and Delete Printers

Post if you need more, but you actually have something that is _very_ simple
to do using VBScript's Filter function. From the docs, the prototype for it
is this:

Filter(InputStrings, Value[, Include[, Compare]])
where InputStrings is an array; Value is the value you're searching for that
should be contained in those strings; Include is a boolean, true (default)
for returning only items containing the string, and false for only returning
items NOT containing it; and Compare is vbBinaryCompare (or 0, for caseful
comparison) or vbTextCompare (or 1, for case-insensitive comparison).

Here's a demo.

printers = Array("\\OLDPRINTSERVER\ptr1", "\\newprintserver\ptr1", _
"\\oldprintserver\ptr2", "\\oldprintserver\ptr3", _
"\\newprintserver\ptr1")

Oldprinters = Filter(printers, "\\OLDPRINTSERVER\", true, vbTextCompare)
for each oldprinter in oldprinters
WScript.Echo oldprinter
next

Filter has limited use in many circumstances since it does simple
comparison, but it works well for this since the \\<name>\ form anchors a
unique string.

"Christopher Beard" <ChristopherBeard@xxxxxx> wrote in
message news:0CB742E6-1E06-4D4C-9823-2B7373A8B445@xxxxxx
Quote:

> We are migrating from one print server to another and the printers from
> the
> old print server still exist on the client PCs and I want to delete them.
> What I am trying to do is write a script to do the following on the client
> PCs:
> 1. List the user's printers
> 2. Pipe that list into an array
> 3. Search the array for printers starting with \\OLDPRINTSERVER
> 4. Delete those printers
> I know how to list printers and delete printers, can someone help with the
> rest? Thank you in advance!
> Christopher
My System SpecsSystem Spec
Old 04-14-2009   #3 (permalink)
Alex K. Angelopoulos


 
 

Re: Need Help With Script To List and Delete Printers

And out of curiosity, what technique are you using to remove the printers?

"Christopher Beard" <ChristopherBeard@xxxxxx> wrote in
message news:0CB742E6-1E06-4D4C-9823-2B7373A8B445@xxxxxx
Quote:

> We are migrating from one print server to another and the printers from
> the
> old print server still exist on the client PCs and I want to delete them.
> What I am trying to do is write a script to do the following on the client
> PCs:
> 1. List the user's printers
> 2. Pipe that list into an array
> 3. Search the array for printers starting with \\OLDPRINTSERVER
> 4. Delete those printers
> I know how to list printers and delete printers, can someone help with the
> rest? Thank you in advance!
> Christopher
My System SpecsSystem Spec
Old 04-15-2009   #4 (permalink)
Christopher Beard


 
 

Re: Need Help With Script To List and Delete Printers

I'm going to try to use a basic VBScript printer delete like below. Thanks
for your help! I'll try this and let you know how it goes.

objNetwork.RemovePrinterConnection "printername"


"Alex K. Angelopoulos" wrote:
Quote:

> And out of curiosity, what technique are you using to remove the printers?
>
> "Christopher Beard" <ChristopherBeard@xxxxxx> wrote in
> message news:0CB742E6-1E06-4D4C-9823-2B7373A8B445@xxxxxx
Quote:

> > We are migrating from one print server to another and the printers from
> > the
> > old print server still exist on the client PCs and I want to delete them.
> > What I am trying to do is write a script to do the following on the client
> > PCs:
> > 1. List the user's printers
> > 2. Pipe that list into an array
> > 3. Search the array for printers starting with \\OLDPRINTSERVER
> > 4. Delete those printers
> > I know how to list printers and delete printers, can someone help with the
> > rest? Thank you in advance!
> > Christopher
>
>
My System SpecsSystem Spec
Old 04-16-2009   #5 (permalink)


XP
 
 

Re: Need Help With Script To List and Delete Printers

I wanted to create a script to do the same action as the OP.

I have a script that will query the local computer and delete all network printers on the machine (see below). I don't want to delete all network printers, but instead want to delete all of the printers from \\DC1. How could I rework this script to include the filter above?

-----=======-----
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Network = True")

For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

Last edited by Aisak; 04-16-2009 at 12:01 PM.. Reason: Update
My System SpecsSystem Spec
Old 04-16-2009   #6 (permalink)
Christopher Beard


 
 

Re: Need Help With Script To List and Delete Printers

Aisak,
I'm having a bit of trouble making this work. If I figure it out, I'll let
you know.
Christopher

"Aisak" wrote:
Quote:

>
> I wanted to write a script using the same method as the OP.
>
> What would a full script to remove all printers from \\OldServer be
> using objNetwork.RemovePrinterConnection as the deletion method. The
> above example confused me a little on how to create the filter to be
> only printers from \\OldServer and how you would then pipe that into the
> RemovePrinterConnection.
>
>
> --
> Aisak
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Cannont delete printers - no jobs pending! Vista print fax & scan
Printers Won't Remove/Delete Vista print fax & scan
Adding fax modem to printers list Vista print fax & scan
is there any script to get a list of COM Objects in a computer? PowerShell
list of printers... PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46