Subscribe

Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts

Search

Archives

Remove offline printers using vbscript

Post image for Remove offline printers using vbscript

by Steve Wiseman on September 13, 2013 · 5 comments

in Scripts,Tips


.

I got a question from Mark this week:

“Hi Steve,

Love your newsletter, keep sending me the good stuff 🙂 I have a question for you. I was wondering if there was a way to delete printers that were offline from a script. This would allow me to clean up dead printers without going around to each computer. My google fu has not been able to turn anything up. – Thanks!”

Excellent question Mark. It took me quite a while to find it, but there is a property in the Win32_Printer object. It is called ExtendedPrinterStatus.

I was able to figure out through experimentation that if ExtendedPrinterStatus is equal to 7, then the printer is offline.

With that info in hand, we can build a simple vb-script that will delete the printer if it is offline:

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

set sInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where ExtendedPrinterStatus = 7")

For Each sPrinter in sInstalledPrinters
 sPrinter.Delete_
Next

Notice the underscore in the delete method – that is needed. Just a little twist added by Microsoft to keep you on your toes. They roll that way

To call it from your script, use the cscript.exe executable. A good example would look like this:

%windir%\system32\cscript.exe \\server\path\offline_printer_cleanup.vbs

Finally – Don’t leave this thing in place all the time. Once you think enough users have logged in and all is cleaned up, I would suggest removing it from their logon script.

Why?

What happens when one of your main printers goes offline?

Yep, those calls start rolling in about a missing printer.

If you are having trouble using cut and paste from the browser, here is a link to the script on our website:

offline_printer_cleanup.dat

Make sure to rename to .vbs after downloading.

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 5 comments… read them below or add one }

1 Hot Dog September 13, 2013 at 11:36 am

Thanks for the tip Steve. Don’t know how you found that ExtendedPrinterStatus but I sure will put it to use!

2 Markus September 17, 2013 at 10:19 am

Will this work on Windows XP?

3 Steve Wiseman September 17, 2013 at 10:19 am

Hi Markus,

It will work fine on XP. Not sure about 2000. I don’y have a 2000 machine here up and running to test anymore 🙂

4 Tim November 30, 2014 at 12:38 pm

Will it work on windows 7 64 bit

5 Steve Wiseman February 13, 2015 at 6:55 am

Yes it will. It should work on all versions of windows up to Windows 10

Leave a Comment

Category Links - Windows Forum - Exchange Forum