Solved

VBS Script to delete all printers except LPT and USB connected

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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…

685 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