Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

script to delete all network printers

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
gedney77090
Asked:
gedney77090
  • 3
  • 2
1 Solution
 
Jared LukerCommented:
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
 
gedney77090Author Commented:
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
 
RobSampsonCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
gedney77090Author Commented:
cleint to print server. I was able to create a script that worked. Thank you for your help.
0
 
RobSampsonCommented:
Oh that's great.  Was it similar to Jared's?  Would you mind sharing your code?

Rob.
0
 
gedney77090Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now