Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting printer status (online/offline)

Posted on 1998-02-06
4
Medium Priority
?
2,519 Views
Last Modified: 2010-04-04
I'd really like to know how to get the status of a printer by it's index in the printer object, in particular I'm interested in getting info about the readyness of the printer (the platform is o'coz NT4+D3).
0
Comment
Question by:dionysos_swamp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1358535
This is from Lloyd's Help file:
Q:  How can I tell if the printer is ON or not?

A:

Program  Printer_Status;
Uses Dos;
Function PrinterOnLine : Boolean;
  Const
    PrnStatusInt  : Byte = $17;    (*  Dos interrupt *)
    StatusRequest : Byte = $02;    (*  Interrupt Function Call *)

    PrinterNum    : Word = 0;  { 0 for LPT1, 1 for LPT2, etc. }
  Var
    Regs : Registers ;         { Type is defined in Dos Unit }

    Begin  (* PrinterOnLine*)
      Regs.AH := StatusRequest;
      Regs.DX := PrinterNum;
      Intr(PrnStatusInt, Regs);
      PrinterOnLine := (Regs.AH and $80) = $80;

    End;

Begin (* Main Program *)
  If PrinterOnLine Then
    Writeln('Ready To Print')
  Else
    Writeln('Please check the printer!');
End.

{ This code came from Lloyd's help file! }
0
 
LVL 1

Author Comment

by:dionysos_swamp
ID: 1358536
interrupts are not acceptable under NT4, I need NT 4 API code, not a dos-hack.
0
 
LVL 5

Accepted Solution

by:
inter earned 400 total points
ID: 1358537
Please use the following function: (sorry for the mess I wrote it in a hurry)

NOTE : include Printers and WinSpool units

procedure TForm1.Button6Click(Sender: TObject);
var
  pcbNeeded : DWord;
  prn : THandle;
  x : array[0..255] of char;
  stat : Pprinterinfo2;
begin
  getmem(stat, 1000);
  try
  StrPCopy(x, printer.printers[0]);
 if OpenPrinter(x, prn, nil) then
  if GetPrinter(
    prn,
    2,      // version of printer info data structure
    stat,      // pointer to array of bytes that receives printer info. structure
    1000,      // size, in bytes, of array of bytes
    @pcbNeeded       // pointer to variable with count of bytes retrieved (or required)
   ) then
   case stat.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 toner.');
   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.');
   end else caption := inttostr(getlasterror);
   ClosePrinter(prn);
  finally
   if stat <> nil then freemem(stat, 1000);
  end;
end;



0
 
LVL 5

Expert Comment

by:inter
ID: 1358538
Excuse me, the ready state is indicated by stat.status = 0, so we should add the CASE statement the following:

  case ...
   .
  else ShowMessage('Ready!');
  end;

(Please try the states of the printer i.e. off, just online-warming up- paused, printing, etc)

Igor
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question