Delete Network Printers using VBScript

The script below will delete all network printers  from the user profile but will not remove any of the local printers. This is quite useful if you have roaming profiles and want to remove mapped printers before running computer/OU specific scripts to map other printers.

You will need to copy the below into a notepad document and save with a .vbs extension.

‘————————————————————————-

‘– Removes all network printers but not any local printers–

‘————————————————————————-

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)

Set colInstalledPrinters =  objWMIService.ExecQuery _
(“Select * from Win32_Printer Where Network = TRUE”)

For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next

‘————————————————————————-

I have tested this under Windows XP and Windows 7 and appears to work properly. I don’t have any more Vista machines but it should work fine on that also.

Share

2 Comments

  • By dirk adamsky, February 19, 2010 @ 11:36 pm

    Script is good but you should close your objects also:
    Set colInstalledPrinters = Nothing
    Set objWMIService = Nothing

  • By helen, May 8, 2010 @ 2:53 am

    objPrinter.delete, I get a runtime error (Object doesn’t support property or method).

Other Links to this Post

RSS feed for comments on this post. TrackBack URI

Leave a comment