Question

Locked

Can I delete printers with certain status using a script?

By martin ·
I'm looking for a script to remove printers from users profiles with the status "Printer not found on server, unable to connect". These printers have been removed from the print server but I need to now run a script to remove them from the user profiles (in a logoff script). After much googling I've been able to find how to remove all printers and recreate those required but I really would like to know if it's possible to delete just those with this specific status.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

This might be useful

by Bizzo In reply to Can I delete printers wit ...

Below is a short script to display all printers in the profile:

------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
For Each objPrinter in colPrinters
WScript.echo objPrinter.Name
strPrinterState = objPrinter.PrinterState
WScript.echo strPrinterState
Next
----------------------------------

The main thing you're looking at here is the "PrinterState" http://msdn.microsoft.com/en-us/library/aa394363(VS.85).aspx
This page lists the possible values (1-25),
Then, depending on the current state, you can delete the printer using "RemovePrinterConnection", see http://www.computerperformance.co.uk/Logon/Logon_Remove_Printer.htm

Back to Networks Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums