2

I did a lot of search and it comes with nothing.Such as below:

c# check printer status

how do i check if a printer is installed and ready using C#?

I tried all the code I found in here but none of them can tell the status of a printer's power is on or off.

The printer is always plugged in and sometimes it's powered off, so I need to make sure it's powered on and then do the print job.

Real need some help here!

question update

the windows still send the print job to print spool when my printer is off, I don't need this, because my client sometimes will deliberately turn off the printer to avoid print something that he don't need. but windows still send it to spool, when my client turn on the printer again, it prints the thing that exactly he want to avoid.

The legacy code uses kernel32.dll's CreateFile function to open LPT1 as a file and directly write string to it to accomplish then printing function. It got no way to know the status of the printer, it just write string to the parallel port. so when the printer is off, the write function got no return, hence the following code after that will never get executed.

hopefully u can understand what I am trying to do here. I want to avoid the situation to print when the printer is off.

Community
  • 1
  • 1
castiel
  • 2,675
  • 5
  • 29
  • 38
  • The [final answer to your second link](http://stackoverflow.com/a/1622931/62576) (last code block) shows how to check the current status via WMI. If the power isn't on, it won't be available and ready, which is all you need to know. (It doesn't matter if it's powered off, offline, the network cable is unplugged, or anything else - if it's not available and ready, you can't print to it. Right?) – Ken White Aug 30 '13 at 02:43
  • @KenWhite yes, I did try that code, but on my system, the status code is no different despite the power status of my printer – castiel Aug 30 '13 at 02:56
  • There are multiple things you can check via WMI (which are in that post). However, I don't understand your issue here. The way Windows print spooling works, I can set up a printer, disconnect my laptop, take it on a trip, send documents to the printer, and then go home a week later and actually print them all, because they're still in the print spool. Your app should just print; Windows will take care of the print job, and the user can take care of whatever is needed to actually get the output. – Ken White Aug 30 '13 at 03:04
  • @KenWhite oh my, maybe u can help me here, u see, The exact problem I am facing is the print spool, when I turn off my printer, windows still send the job into spool and the print function that I use got no return until I turn on the printer. Now I need to not send the print job when my printer is off. – castiel Aug 30 '13 at 03:09
  • Your expectations are wrong. Your code shouldn't care if the printer is actually on or off; it should just print and return. It is *supposed to* go to the spool and sit there until the printer is turned on; that's the way it works. (If the printer is turned off, out of paper, off-line, jammed, or something else, your code shouldn't care. It should just print, because that's what the user told it to do.) – Ken White Aug 30 '13 at 03:14
  • @KenWhite please see my updated question and give me some advices – castiel Aug 30 '13 at 03:18

0 Answers0