Solved

script to delete all network printers

Posted on 2008-06-09
6
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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