Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
My children constantly leave the printer on.
I wanted a test to be run at shutdown to see if the printer is on. This is what a kind person sent to me but I really do not know how to use the information.
My printer is a HP photosmart 7150objPrinter.PrinterStatus=3 is the "ready" printer state
strPrinter should be set to the name of the printer
strComputer really isn't necessary as it is just the local PC.. force of habit for me.
Code:'run at shutdown to check the status of a printer
Option Explicit
Dim objWMI, objPrinter, colPrinters, strComputer,strPrinter,strWMIQuerystrComputer = "."
strPrinter = "Some Printer Name"
strWMIQuery = "SELECT * FROM Win32_Printer WHERE name=""" & strPrinter & """"set objWMI = GetObject ("winmgmts:\\" & strComputer & "\root\CIMV2")
set colPrinters = objWMI.ExecQuery(strWMIQuery)
for each objPrinter in colPrinters
if not(objPrinter.PrinterStatus=3) then
msgbox "Turn off the Printer!",0,"Printer Is Still On!"
end if
nextwscript.quit

This is Visual Basic code. You need to incorporate it into a VB Script file and set the VB script to run at close down.
This method is not fool-proof. Some printers report Ready even when the printer is turned off, simply the absence of any error messages. It all depends on the sophistication of the printer driver. You should be all right with an HP printer though.
http://techsupt.winbatch.com/ts/T00...
Stuart

Thanks for that. What I did not know was how to adapt the script to make it work. I need to know what goes into strPrinter = "Some Printer Name". Also what needs to go between the """,if you could help please.

Some Printer Name should be replaced by the Name of your Printer. Look in the Printer and Faxes Screen for the name of the printer.
Nothing goes between the """. It is used as written. Notice there are two groups of three quotes, double quotes within quotes. It is to put quotes around the variable strPrinter within the string strWMIQuery. Without it strPrinter would be treated as a literal string which wouldn't work. It would be looking for a printer called strPrinter instead of HP photosmart 7150 or whatever the printer is called.
If you had any experience of SQL you would recognise it as SQL syntax.
Stuart

Thank you for your time on this. I still have no success. I have managed to get some error codes by changing things around. So perhaps your original assertion that it may not work is infact the case.
Thank you again

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |