Solved

script to delete all network printers

Posted on 2008-06-09
6
280 Views
Last Modified: 2010-04-16
I am the worst at scripting. I am looking for a VB script that will allow users to delete all exisitng network printers so that we can assign new ones.
0
Comment
Question by:gedney77090
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:Jared Luker
ID: 21747804
Hello gedney77090,

Here you go...

Good Luck,

Jared
----------------------------------------------------
'Remove all Network printers but not local printers
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections 
For i = 0 to Printers.Count - 1 Step 2 
    If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
        WScript.Echo Printers.Item(i+1)
        WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
    End IF
Next

Open in new window

0
 

Author Comment

by:gedney77090
ID: 21750571
I ran the script and windows popped up that said the printers would be deleted but they remained at the termination of the script.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21755346
Are the printers connected directly to the print server from the client, or have you created the local TCP/IP ports to connect the printer to?

Regards,

Rob.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:gedney77090
ID: 21755409
cleint to print server. I was able to create a script that worked. Thank you for your help.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21755527
Oh that's great.  Was it similar to Jared's?  Would you mind sharing your code?

Rob.
0
 

Accepted Solution

by:
gedney77090 earned 0 total points
ID: 21958490
Option Explicit
Dim objNetwork, strLocal, strUNCPrinter1, strUNCPrinter2
strUNCPrinter1 = "\\ptsvprt01\PTPR064"
strUNCPrinter2 = "\\ptsvprt01\PTPR067CP"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
WScript.Quit


Here is the code that worked
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When I recently replaced my image transfer kit on my office HP color laserjet 5550dn printer, I had a slight problem.  The left bracket that holds the transfer kit got stuck in the upright locked position instead of being at a 45 degree angle facing…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now