I tried a few times to figure this out, but all of my attempts failed, so I do not think this is possible. I tried all morning and wound up with this, but even this fails when a HP printer/scanner is powered off:
procedure TForm1.PrinterStatus1Click(Sender: TObject);
var
iPrinterIndex: integer;
pcbNeeded: DWORD;
iPrinter: THandle;
iPrinterName: array [0 .. 255] of char;
iPrinterInfo2: PPrinterInfo2;
begin
GetMem(iPrinterInfo2, 5000);
try
iPrinterIndex := GetDefaultPrinterIndex;
StrPCopy(iPrinterName, Printer.Printers[iPrinterIndex]);
if OpenPrinter(iPrinterName, iPrinter, nil) then
if GetPrinter(iPrinter, 2, iPrinterInfo2, 5000, @pcbNeeded) then
case iPrinterInfo2.Status of
PRINTER_STATUS_BUSY:
ShowMessage('The printer is busy.');
PRINTER_STATUS_DOOR_OPEN:
ShowMessage('The printer door is open.');
PRINTER_STATUS_ERROR:
ShowMessage('The printer is in an error state.');
PRINTER_STATUS_INITIALIZING:
ShowMessage('The printer is initializing.');
PRINTER_STATUS_IO_ACTIVE:
ShowMessage('The printer is in an active input/output state.');
PRINTER_STATUS_MANUAL_FEED:
ShowMessage('The printer is in a manual feed state.');
PRINTER_STATUS_NO_TONER:
ShowMessage('The printer is out of toner.');
PRINTER_STATUS_NOT_AVAILABLE:
ShowMessage('The printer is not available for printing.');
PRINTER_STATUS_OFFLINE:
ShowMessage('The printer is offline.');
PRINTER_STATUS_OUT_OF_MEMORY:
ShowMessage('The printer has run out of memory.');
PRINTER_STATUS_OUTPUT_BIN_FULL:
ShowMessage('The printers output bin is full.');
PRINTER_STATUS_PAGE_PUNT:
ShowMessage('The printer cannot print the current page.');
PRINTER_STATUS_PAPER_JAM:
ShowMessage('Paper is jammed in the printer');
PRINTER_STATUS_PAPER_OUT:
ShowMessage('The printer is out of paper.');
PRINTER_STATUS_PAPER_PROBLEM:
ShowMessage('The printer has a paper problem.');
PRINTER_STATUS_PAUSED:
ShowMessage('The printer is paused.');
PRINTER_STATUS_PENDING_DELETION:
ShowMessage('The printer is deleting a print job.');
PRINTER_STATUS_PRINTING:
ShowMessage('The printer is printing.');
PRINTER_STATUS_PROCESSING:
ShowMessage('The printer is processing a print job.');
PRINTER_STATUS_TONER_LOW:
ShowMessage('The printer is low on ink.');
PRINTER_STATUS_USER_INTERVENTION:
ShowMessage('The user needs to do something to the printer.');
PRINTER_STATUS_WAITING:
ShowMessage('The printer is waiting.');
PRINTER_STATUS_WARMING_UP:
ShowMessage('The printer is warming up.');
PRINTER_STATUS_SERVER_UNKNOWN:
ShowMessage('Printer server unknown.');
PRINTER_STATUS_POWER_SAVE:
ShowMessage('Printer in power saving mode.');
PRINTER_STATUS_SERVER_OFFLINE:
ShowMessage('Printer server is off line.');
else
ShowMessage('The printer is online and is ready to print.');
end
else
Caption := IntToStr(GetLastError);
ClosePrinter(iPrinter);
finally
if iPrinterInfo2 <> nil then
FreeMem(iPrinterInfo2, 5000);
end;
end;
Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development