Solved

VBS Script for Deleting Printers IF they Exist.

Posted on 2014-04-18
2
200 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 27

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Lee
Windows 7 Ultimate and Enterprise (and 2008 R2) introduced a new feature you may not be aware of - Boot from VHD.   Boot from VHD (or what Microsoft refers to asNative Boot allows you to install Windows to a VHD (Virtual Hard Disk) file that is t…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

706 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

21 Experts available now in Live!

Get 1:1 Help Now