?
Solved

VBS Script for Deleting Printers IF they Exist.

Posted on 2014-04-18
2
Medium Priority
?
215 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
[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
2 Comments
 
LVL 30

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 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
Assume you have an outside contractor who comes in seasonally or once a week to do some work in your office, but you only want to give him access to the programs and files he needs and keep all other documents and programs private. Can you do this o…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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