Solved

VBS Script for Deleting Printers IF they Exist.

Posted on 2014-04-18
2
203 Views
Last Modified: 2014-04-21
We're in the process of replacing new printers in my office. We currently have around 170 users, and I need a script that will run at login, to check for old printers and if one of the old printers exists, it is deleted.

We already have a login script to create the printers, which uses the "objNetwork.AddWindowsPrinterConnection" command. I just need one to run right before it, to delete the old printers.

Any ideas?

Thanks in advance!
0
Comment
Question by:Subnet_This
2 Comments
 
LVL 28

Expert Comment

by:serialband
ID: 40009840
From https://social.technet.microsoft.com/Forums/en-US/5141787d-9ac0-4e03-9b76-08de7db1530f/vbscript-to-delete-current-printers-and-add-new-printers

strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colInstalledPrinters =  objWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = TRUE") For Each objPrinter in colInstalledPrinters objPrinter.Delete_

Open in new window

0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 40011851
i just use objNetwork.DeletePrinter   with On Error Resume Next  before it.

it deletes all the printers found, skipping those not found.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Remote Assistance 5 25
How do I hook up a bluetooth speaker? 20 94
Update on Win 7 30 72
NTFS permissions - creator owner 2 21
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now