Solved

VBS Script to delete all printers except LPT and USB connected

Posted on 2008-10-21
2
1,350 Views
Last Modified: 2012-05-05
I need a VBS Script to delete ALL printers EXCEPT LPT and USB connected.  This includes deleting printers setup to use IP Addresses locally.  All the PC's will have WinXP as the OS.  I'm using for a logon script.
0
Comment
Question by:MainStaySolutions
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22771485
Paste the script below into a text file with a .vbs extension.  Running it will remove all printers except those whose port names begin with LPT or USB.

Keep in mind that ordinary users may not have sufficient rights to delete local printers.  It might be better to run this as a startup script rather than (or in addition to) as a logon script in order to ensure that local printers are removed.

Please test this carefully before running it in a production environment.


'Adapted from http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov07/hey1102.mspx

strComputer = "."
 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 

Set colInstalledPrinters = objWMIService.ExecQuery _

    ("Select * From Win32_Printer")
 

For Each objPrinter in colInstalledPrinters

    If Not (Left(objPrinter.Portname, 3) = "LPT" Or Left(objPrinter.Portname, 3) = "USB") Then

        objPrinter.Delete_

    End If

Next

Open in new window

0
 

Author Closing Comment

by:MainStaySolutions
ID: 31508503
That worked.  Thanks for speedy response.
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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
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 …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

14 Experts available now in Live!

Get 1:1 Help Now