How to Delete All Printers With VBScript

Written by janet leste
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Delete All Printers With VBScript
Use VBScript to remove printers. (keyboard image by Orlando Florin Rosu from

Windows supports several scripting languages, including Visual Basic Scripting Edition, or VBScript. With intuitive, English-like syntax, VBScript is an easy language to learn. VBScript alone is an environment suitable for many common administrative tasks, but its greater value comes from its ability to interact with other components of the operating system, such as the Windows Management Instrumentation Service (WMI). WMI stores detailed information about your computer and can be used in conjunction with VBScript to monitor or find out the state of any component that conforms to the WMI standards, including adding or deleting printer objects.

Skill level:

Things you need

  • Microsoft Windows 2000 or newer

Show MoreHide


  1. 1

    Log on to your computer with an account that has administrative permissions.

  2. 2

    Open Windows Notepad by typing "notepad" into the search field on the "Start" menu. If you are using Windows XP, click "Start" and then "Run ... ," type "notepad" and press "OK."

  3. 3

    Click "Format" on the menu bar in Notepad, then select "Word Wrap" to toggle that feature off. This will make your script easier to read.

  4. 4

    Type strComputer = "." on the first line of the file. This indicates that you want the script to run against the local computer. If you want to run the script against another computer and have the appropriate permissions, you can replace "." with the name of the remote computer.

  5. 5

    Add the following line of code to your script. Before you can query the WMI service for information about the computer, VBScript must first attach, or bind, to that service.

    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

  6. 6

    Query the WMI service for a list of all the printers installed on the local computer, and for each printer found, confirm deletion. Complete the script by entering the following code:

    Set col Printers = objWMIService.ExecQuery("Select * from Win32_Printer")

    For Each objPrinter in col Printers

     ret = MsgBox("Are you sure you want to delete the following printer: " & objPrinter.Name, vbYesNo, "Confirm Printer Deletion")
    If ret = 6 Then

    End if



  7. 7

    Save the Notepad file with the extension *.vbs, and then double-click the file to launch the script.

Tips and warnings

  • If you want to view a list of installed printers without actually deleting them, change the line of code that reads "objPrinter.Delete_" to "Wscript.Echo objPrinter.Name."
  • Running the code will delete all local and network printer objects from the local computer. If you delete a printer inadvertently, use the "Add Printer" wizard to reinstall it.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.