1
votes

I've been using the win32print module for Python to try to get various information about sets of printers, such as driver name, job count, port being used, status, etc. It's been mostly successful, however I am having a lot of trouble making any use of the status code that win32print returns from the API.

I've been using the win32print.GetPrinter method, which returns a PRINTER_INFO_ dictionary, with one mapping being Status. However, it isn't documented what status code corresponds to what printer status. It seems that 0 is idle, 1 is paused, but other than that I'm not sure what it means.

When I looked up values of constants for the windows 32bit API, I found this page, but none of the status codes I ever get back seem to match that. Often times, I get a status code like 1052800 (got that one from an Epson printer), which is not on the list from the win32api constants.

I have also tried using WMI modules to do this with even less success.

I would like to get printer status codes for printer out of paper, printer door open, toner low, paper jam, etc. Does anyone have any tips on where to find what these status codes mean, or even a better solution to finding printer status completely?

2

2 Answers

1
votes

The status returned is a bitmask, which is described for example here. Multiple values can be ORed together, so your value 1052800 (hex 0x101080) means the printer has (all of the) statuses;

  • PRINTER_STATUS_USER_INTERVENTION
  • PRINTER_STATUS_NOT_AVAILABLE
  • PRINTER_STATUS_OFFLINE
0
votes

I would like to share my experience in Windows 10 to check if the printer is offline or not. Status flag in the PRINTER_INFO_2 from win32print.GetPrinter is not working for me, because it always be 0 for all installed printers. Thanks for this stackoverflow discussion for C++, I found that PRINTER_ATTRIBUTE_WORK_OFFLINE flag in printer attributes can represent if printer in offline status.

handle = win32print.OpenPrinter(printer_name)   
attributes = win32print.GetPrinter(handle)[13]
print(f'{printer_name} is offline? :{(attributes & 0x00000400) >> 10}')

[13] is the attribute position in returned tuple. microsoft doc
0x00000400 is the hex code of PRINTER_ATTRIBUTE_WORK_OFFLINE. microsoft doc