Solved

VBS Script to delete all printers except LPT and USB connected

Posted on 2008-10-21
2
1,357 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

825 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