Solved

Remove printer by command line (script) on several machines

Posted on 2008-06-11
7
7,521 Views
Last Modified: 2011-10-19
Hi,

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:
HPPrinter1
HPCopier2

OS:
XP

High points b/c this needs to be done asap
0
Comment
Question by:peshih7
[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
7 Comments
 
LVL 5

Expert Comment

by:pbeirne
ID: 21761640
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

Wscript.Quit

0
 

Author Comment

by:peshih7
ID: 21761715
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?

Thanks
0
 

Author Comment

by:peshih7
ID: 21761792
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
Picture-14.png
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
LVL 5

Accepted Solution

by:
pbeirne earned 400 total points
ID: 21762305
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.
0
 
LVL 5

Expert Comment

by:pbeirne
ID: 21762548
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(objPrinter.name) = Lcase(strPrinter1) Then  
 
Set objNetwork = CreateObject("Wscript.Network")  
 
objNetwork.RemovePrinterConnection strPrinter1  
 
Else  
 
If Lcase(objPrinter.name) = Lcase(strPrinter2) Then  
 
Set objNetwork = CreateObject("Wscript.Network")  
 
objNetwork.RemovePrinterConnection strPrinter2  
 
End If  
 
End If  
 
Next
'End Script
0
 

Expert Comment

by:Exirtis
ID: 23692937
I have found that the following script works great:

RUNDLL32 printui.dll,PrintUIEntry /n \\server\printer.name /dl
0
 

Expert Comment

by:neerjajha
ID: 34902188
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?
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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