[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBS Script for Deleting Printers IF they Exist.

Posted on 2014-04-18
2
Medium Priority
?
220 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
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…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses

656 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