[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1422
  • Last Modified:

VBS Script to delete all printers except LPT and USB connected

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
MainStaySolutions
Asked:
MainStaySolutions
1 Solution
 
Shift-3Commented:
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
 
MainStaySolutionsAuthor Commented:
That worked.  Thanks for speedy response.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now