Remove printer by command line (script) on several machines


We are about to phase out a few of our network printers and replace them with new ones.  Currently we can deploy all the new printers to users without problems but the old printers still remain in their printer lists.

How can I make a script to remove ONLY these certain printers from each users PC?

Printer names:


High points b/c this needs to be done asap
Who is Participating?
pbeirneConnect With a Mentor Commented:
put the following line at the top of the script:

On Error Resume Next

Let me know if that takes care of your errors.  I've only used scripts to remove one printer or all printers, so to remove a couple of specific printers requires a little tweaking of the script.

I've got another script I am modifying to delete your two specific printers we can try if this one doesn't work.  Let me know.
If they are network printers you can try this in a .vbs file

' Begin Code
Option Explicit
Dim objNetwork, strPrinter1, strPrinter2
strPrinter1 = "\\server\HPPrinter1"
strPrinter2 = "\\server\HPCopier2"

Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection strPrinter1
objNetwork.RemovePrinterConnection strPrinter2


peshih7Author Commented:
Script worked great.  Are there any permissions issues with this?  Will my users (domain users) be able to run this if I use it as a login script?

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

peshih7Author Commented:
Ok so script worked but I ran into this problem.

If any one of the printers is already removed the script throws and error and does not resume to the other printers, how can I make the script continue even on error.

If I can make it so the error doesnt display that would be great too.

Error is attached
Here's an alternative script that should handle errors and user rights.  Obviously change the path to your printers for strPrinter1 & 2.

'Begin Script
strComputer = "."
strPrinter1 = "\\server\HPPrinter1"
strPrinter2 = "\\server\HPCopier2"

Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")  
Set colPrinters = objWMI.ExecQuery("Select * From Win32_Printer")  
For Each objPrinter in colPrinters  
on error resume next  
If Lcase( = Lcase(strPrinter1) Then  
Set objNetwork = CreateObject("Wscript.Network")  
objNetwork.RemovePrinterConnection strPrinter1  
If Lcase( = Lcase(strPrinter2) Then  
Set objNetwork = CreateObject("Wscript.Network")  
objNetwork.RemovePrinterConnection strPrinter2  
End If  
End If  
'End Script
I have found that the following script works great:

RUNDLL32 printui.dll,PrintUIEntry /n \\server\ /dl
I have a remote mahcine and it has a network printer installed. I would to to delete that network printer from that machine. How I can do so remotely?
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.

All Courses

From novice to tech pro — start learning today.