Computing.Net > Forums > Programming > Printer Test

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Printer Test

Reply to Message Icon

Name: toast (by NoIdea)
Date: April 18, 2008 at 03:08:43 Pacific
OS: XP Pro
CPU/Ram: 2.3/1 gig
Product: EMachines 580
Comment:

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 7150

objPrinter.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,strWMIQuery

strComputer = "."
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
next

wscript.quit



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: April 18, 2008 at 11:24:20 Pacific
Reply:

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


0

Response Number 2
Name: toast (by NoIdea)
Date: April 18, 2008 at 12:08:11 Pacific
Reply:

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.


0

Response Number 3
Name: StuartS
Date: April 18, 2008 at 14:18:45 Pacific
Reply:

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


0

Response Number 4
Name: toast (by NoIdea)
Date: April 19, 2008 at 03:52:19 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Printer Test

using WSH to install print drivers www.computing.net/answers/programming/using-wsh-to-install-print-drivers/2592.html

Printer initilisation problem www.computing.net/answers/programming/printer-initilisation-problem/1560.html

Serial port test using LED www.computing.net/answers/programming/serial-port-test-using-led/12226.html