Solved

script to delete all network printers

Posted on 2008-06-09
6
282 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

822 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