Solved

VBS Script to delete all printers except LPT and USB connected

Posted on 2008-10-21
2
1,374 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
[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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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