Solved

how to check printer status

Posted on 1998-04-28
10
413 Views
Last Modified: 2008-02-01
How can I check printer status ?
0
Comment
Question by:can9999
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1433366
Haven't tried it but here is all I could find so far on it:

Public Const PRINTER_ATTRIBUTE_DEFAULT = &H4
Public Const PRINTER_ATTRIBUTE_DIRECT = &H2
Public Const PRINTER_ATTRIBUTE_ENABLE_BIDI = &H800
Public Const PRINTER_ATTRIBUTE_HIDDEN = &H20
Public Const PRINTER_ATTRIBUTE_LOCAL = &H40
Public Const PRINTER_ATTRIBUTE_NETWORK = &H10
Public Const PRINTER_ATTRIBUTE_QUEUED = &H1
Public Const PRINTER_ATTRIBUTE_SHARED = &H8
Public Const PRINTER_ATTRIBUTE_WORK_OFFLINE = &H400

Public Const PRINTER_STATUS_BUSY = &H200
Public Const PRINTER_STATUS_DOOR_OPEN = &H400000
Public Const PRINTER_STATUS_ERROR = &H2
Public Const PRINTER_STATUS_INITIALIZING = &H8000
Public Const PRINTER_STATUS_IO_ACTIVE = &H100
Public Const PRINTER_STATUS_MANUAL_FEED = &H20
Public Const PRINTER_STATUS_NO_TONER = &H40000
Public Const PRINTER_STATUS_NOT_AVAILABLE = &H1000
Public Const PRINTER_STATUS_OFFLINE = &H80
Public Const PRINTER_STATUS_OUT_OF_MEMORY = &H200000
Public Const PRINTER_STATUS_OUTPUT_BIN_FULL = &H800
Public Const PRINTER_STATUS_PAGE_PUNT = &H80000
Public Const PRINTER_STATUS_PAPER_JAM = &H8
Public Const PRINTER_STATUS_PAPER_OUT = &H10
Public Const PRINTER_STATUS_PAPER_PROBLEM = &H40
Public Const PRINTER_STATUS_PAUSED = &H1
Public Const PRINTER_STATUS_PENDING_DELETION = &H4
Public Const PRINTER_STATUS_PRINTING = &H400
Public Const PRINTER_STATUS_PROCESSING = &H4000
Public Const PRINTER_STATUS_TONER_LOW = &H20000
Public Const PRINTER_STATUS_USER_INTERVENTION = &H100000
Public Const PRINTER_STATUS_WAITING = &H2000
Public Const PRINTER_STATUS_WARMING_UP = &H10000


Type PRINTER_INFO_1
        flags As Long
        pDescription As String
        pName As String
        pComment As String
End Type

Type PRINTER_INFO_2
        pServerName As String
        pPrinterName As String
        pShareName As String
        pPortName As String
        pDriverName As String
        pComment As String
        pLocation As String
        pDevMode As DEVMODE
        pSepFile As String
        pPrintProcessor As String
        pDatatype As String
        pParameters As String
        pSecurityDescriptor As SECURITY_DESCRIPTOR
        Attributes As Long
        Priority As Long
        DefaultPriority As Long
        StartTime As Long
        UntilTime As Long
        Status As Long
        cJobs As Long
        AveragePPM As Long
End Type

Type PRINTER_INFO_5
        pPrinterName As String
        pPortName As String
        Attributes As Long
        DeviceNotSelectedTimeout As Long
        TransmissionRetryTimeout As Long
End Type

Declare Function GetPrinter Lib "winspool" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Boolean

C Explanation of GetPrinter:
The GetPrinter function retrieves information about a specified printer.
BOOL GetPrinter(
    HANDLE hPrinter,      // handle to printer of interest
    DWORD Level,      // version of printer info data structure
    LPBYTE pPrinter,      // pointer to array of bytes that receives printer info. structure
    DWORD cbBuf,      // size, in bytes, of array of bytes
    LPDWORD pcbNeeded       // pointer to variable with count of bytes retrieved (or required)
   );      
 
Parameters
hPrinter
Handle to the printer of interest.
Level
Specifies the level, or type, of PRINTER_INFO_* structure that the function stores into the buffer pointed to by pPrinter.
Windows 95: This value can be 1, 2, or 5.
Windows NT: This value can be 1, 2, 3, 4, or 5.
pPrinter
Pointer to a buffer that receives a PRINTER_INFO_* structure. This structure contains information about the specified printer. The type of structure is determined by the value of Level.
Windows 95: The buffer can receive a PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_5 structure.
Windows NT: The buffer can receive a PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, or PRINTER_INFO_5 structure.
cbBuf
Specifies the size, in bytes, of the buffer pointed to by pPrinter.
pcbNeeded
Pointer to a variable that the function sets to the size in bytes of the printer information. If cbBuf is smaller than this value, GetPrinter fails, and the value represents the required buffer size. If cbBuf is equal to or greater than this value, GetPrinter succeeds, and the value represents the number of bytes stored into the buffer.
 
Return Values
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
If the structure returned in the buffer pointed to by the pPrinter parameter contains a pointer to a security descriptor, only those components of the security descriptor that the caller has permission to read will be present. An application that wants to retrieve particular security descriptor components must open the printer with sufficient access permission. The following table shows the security descriptor components that are retrieved for particular access permission values:
Access Permission      Security Descriptor Components Retrieved
READ_CONTROL      Owner, Primary Group, Discretionary access-control list (ACL)
ACCESS_SYSTEM_SECURITY      System ACL
 
See Also
AbortPrinter, AddPrinter, ClosePrinter, DeletePrinter, EnumPrinters, PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, PRINTER_INFO_5, OpenPrinter, SetPrinter

The PRINTER_INFO_1 structure specifies general printer information.
typedef struct _PRINTER_INFO_1 { // pri1  
    DWORD  Flags;
    LPTSTR pDescription;
    LPTSTR pName;
    LPTSTR pComment;
} PRINTER_INFO_1;
 
Members
Flags
Specifies information about the returned data. Following are the values for this member
Value      Meaning
PRINTER_ENUM_EXPAND      A print provider can set this flag as a hint to a calling application to enumerate this object further if default expansion is enabled. For example, when domains are enumerated, a print provider might indicate the user's domain by setting this flag.
PRINTER_ENUM_CONTAINER      If this flag is set, the printer object may contain enumerable objects. For example, the object may be a print server that contains printers.
PRINTER_ENUM_ICON1      Indicates that, where appropriate, an application should display an icon identifying the object as a top-level network name, such as Microsoft Windows Network.
PRINTER_ENUM_ICON2      Indicates that, where appropriate, an application should display an icon that identifies the object as a network domain.
PRINTER_ENUM_ICON3      Indicates that, where appropriate, an application should display an icon that identifies the object as a print server.
PRINTER_ENUM_ICON4      Reserved for future use.
PRINTER_ENUM_ICON5      Reserved for future use.
PRINTER_ENUM_ICON6      Reserved for future use.
PRINTER_ENUM_ICON7      Reserved for future use.
PRINTER_ENUM_ICON8      Indicates that, where appropriate, an application should display an icon that identifies the object as a printer.
 
pDescription
Windows NT: Points to a null-terminated string that describes the contents of the structure.
Windows 95: Points to a null-terminated string that describes the printer. The string contains the pPrinterName, pDriverName, and pComment members of the PRINTER_INFO_2 structure concatenated and separated by commas.
pName
Windows NT: Points to a null-terminated string that names the contents of the structure.
Windows 95: Points to a null-terminated string that specifies the name of the printer.
pComment
Windows NT: Points to a null-terminated string that contains additional data describing the structure.
Windows 95: Points to a null-terminated string that provides a brief description of the printer.
 
See Also
GetPrinter, EnumPrinters, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4

The PRINTER_INFO_2 structure specifies detailed printer information.
typedef struct _PRINTER_INFO_2 { // pri2  
    LPTSTR    pServerName;
    LPTSTR    pPrinterName;
    LPTSTR    pShareName;
    LPTSTR    pPortName;
    LPTSTR    pDriverName;
    LPTSTR    pComment;
    LPTSTR    pLocation;
    LPDEVMODE pDevMode;
    LPTSTR    pSepFile;
    LPTSTR    pPrintProcessor;
    LPTSTR    pDatatype;
    LPTSTR    pParameters;
    PSECURITY_DESCRIPTOR pSecurityDescriptor;
    DWORD     Attributes;
    DWORD     Priority;
    DWORD     DefaultPriority;
    DWORD     StartTime;
    DWORD     UntilTime;
    DWORD     Status;
    DWORD     cJobs;
    DWORD     AveragePPM;
} PRINTER_INFO_2;
 
Members
pServerName
Points to a null-terminated string identifying the server that controls the printer. If this string is NULL, the printer is controlled locally.
pPrinterName
Points to a null-terminated string that specifies the name of the printer.
pShareName
Points to a null-terminated string that identifies the sharepoint for the printer. (This string is used only if the PRINTER_ATTRIBUTE_SHARED constant was set for the Attributes member.)
pPortName
Points to a null-terminated string that identifies the port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port must be separated by commas (for example, "LPT1:,LPT2:,LPT3:").
pDriverName
Points to a null-terminated string that specifies the name of the printer driver.
pComment
Points to a null-terminated string that provides a brief description of the printer.
pLocation
Points to a null-terminated string that specifies the physical location of the printer (for example, "Bldg. 38, Room 1164").
pDevMode
Points to a DEVMODE structure that defines default printer data such as the paper orientation and the resolution.
pSepFile
Points to a null-terminated string that specifies the name of the file used to create the separator page. This page is used to separate print jobs sent to the printer.
pPrintProcessor
Points to a null-terminated string that specifies the name of the print processor used by the printer.
pDatatype
Points to a null-terminated string that specifies the data type used to record the print job.
pParameters
Points to a null-terminated string that specifies the default print-processor parameters.
pSecurityDescriptor
Points to a SECURITY_DESCRIPTOR structure for the printer. This member may be NULL.
Attributes
Specifies the printer attributes. This member can be one of the following values:
PRINTER_ATTRIBUTE_DEFAULT
PRINTER_ATTRIBUTE_DIRECT
PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST
PRINTER_ATTRIBUTE_ENABLE_BIDI (Windows 95 only)
PRINTER_ATTRIBUTE_ENABLE_DEVQ
PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS
PRINTER_ATTRIBUTE_QUEUED
PRINTER_ATTRIBUTE_SHARED
PRINTER_ATTRIBUTE_WORK_OFFLINE (Windows 95 only)
Priority
Specifies a priority value that the spooler uses to route print jobs.
DefaultPriority
Specifies the default priority value assigned to each print job.
StartTime
Specifies the earliest time at which the printer will print a job. This value is expressed as minutes elapsed since 12:00 A.M. GMT (Greenwich Mean Time).
UntilTime
Specifies the latest time at which the printer will print a job. This value is expressed as minutes elapsed since 12:00 A.M. GMT (Greenwich Mean Time).
Status
Specifies the printer status. This member can be one of the following values:    
Windows NT:
PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DELETION
Windows 95:
PRINTER_STATUS_BUSY
PRINTER_STATUS_DOOR_OPEN
PRINTER_STATUS_ERROR
PRINTER_STATUS_INITIALIZING
PRINTER_STATUS_IO_ACTIVE
PRINTER_STATUS_MANUAL_FEED
PRINTER_STATUS_NO_TONER
PRINTER_STATUS_NOT_AVAILABLE
PRINTER_STATUS_OFFLINE
PRINTER_STATUS_OUT_OF_MEMORY
PRINTER_STATUS_OUTPUT_BIN_FULL
PRINTER_STATUS_PAGE_PUNT
PRINTER_STATUS_PAPER_JAM
PRINTER_STATUS_PAPER_OUT
PRINTER_STATUS_PAPER_PROBLEM
PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DELETION
PRINTER_STATUS_PRINTING
PRINTER_STATUS_PROCESSING
PRINTER_STATUS_TONER_LOW
PRINTER_STATUS_UNAVAILABLE
PRINTER_STATUS_USER_INTERVENTION
PRINTER_STATUS_WAITING
PRINTER_STATUS_WARMING_UP
cJobs
Specifies the number of print jobs that have been queued for the printer.
AveragePPM
Specifies the average number of pages per minute that have been printed on the printer.
 
Remarks
Windows 95: The PRINTER_STATUS_PAGE_PUNT value specifies that the page is being "punted" (that is, not printed) because it is too complex for the printer to print.
See Also
DEVMODE, EnumPrinters, PRINTER_INFO_1, PRINTER_INFO_3, PRINTER_INFO_4, SECURITY_DESCRIPTOR

The PRINTER_INFO_5 structure specifies detailed printer information.
typedef struct _PRINTER_INFO_5 { // pri5  
    LPTSTR    pPrinterName;
    LPTSTR    pPortName;
    DWORD     Attributes;
    DWORD     DeviceNotSelectedTimeout;
    DWORD     TransmissionRetryTimeout;
} PRINTER_INFO_5;
 
Members
pPrinterName
Pointer to a null-terminated string that specifies the name of the printer.
pPortName
Pointer to a null-terminated string that identifies the port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port must be separated by commas (for example, "LPT1:,LPT2:,LPT3:").
Attributes
Specifies the printer attributes. This member can be one of the following values:
PRINTER_ATTRIBUTE_QUEUED
PRINTER_ATTRIBUTE_DIRECT
PRINTER_ATTRIBUTE_DEFAULT
PRINTER_ATTRIBUTE_SHARED
PRINTER_ATTRIBUTE_WORK_OFFLINE
DeviceNotSelectedTimeout
Windows 95: Specifies the maximum time, in milliseconds, allowed to elapse between attempts to select a device.
Windows NT: This value is not used.
TransmissionRetryTimeout
Windows 95: Specifies the maximum time, in milliseconds, allowed to elapse between transmission retries.
Windows NT: This value is not used.
 
See Also
EnumPrinters, GetPrinter, SetPrinter, PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1433367
The property Printer.Page Returns the current page being sent to the printer.  (Since your app started, or the last time you sent Printer.EndDoc)

This assumes, of course, that you are printing using the printer object.  If you use the API to print, this won't work.
0
 
LVL 1

Author Comment

by:can9999
ID: 1433368
Tward !
  - I already tried it, but failed.(always return NULL)
  - I don't how to get printer handle (I'd get it "printer.hdc")

clifABB !
  - Sure, Printer.Page is .
  - But I want to know the method which it is able to use
    under printing with CrystalReport (.Action).


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1433369
Sorry.  I was assuming you were printing from VB.

Good luck.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1433370
The Crystal Reports ocx has a status property.  Use a timer to occasionally poll this property to see if the printing has finished:

Private Sub Timer1_Timer()
  If Report1.Status = 3 Then
    g_bReportDone = True
  ElseIf Report1.Status = 5 Then
    g_bReportCanceled = True
  Else
    g_bReportDone = False
    g_bReportCanceled = False
  End If
End Sub
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:can9999
ID: 1433371
Did you try it ?

I used "Action".

Status value is "3" when printing is on.
But It doesn't clear although printing is over. Alway "3".

Please, try it.


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1433372
When you call Report1.Action = 1, the Status property resets to 0, when the complete document has been sent to the printer the Status property will be set to 3.  It will remain at 3 until you use Action = 1 again.
This property only measures the status of the document sent to the printer (usually a very short time depending on the number of pages and the amount of printer memory), not the actual printer actions (which can be as slow as 2-3 ppm).
0
 
LVL 4

Expert Comment

by:zsi
ID: 1433373
can9999,

If you are using VB5 (or an ealier version of VB with SpyWorks or similar subclassing control), you can trap for the WM_SPOOLERSTATUS message.

This message is sent to every top level window in the system whenever a print jpb is added or removed from the print queue, regardless of its source.  It also will tell you the total number of jobs in the print queue.

Hope this helps!
zsi
0
 
LVL 1

Author Comment

by:can9999
ID: 1433374
zsi !

How can I use "WM_SPOOLERSTATUS" ?
0
 
LVL 4

Accepted Solution

by:
zsi earned 50 total points
ID: 1433375
As I stated before, you will have to use a Message Hook/Subclassing control such as SpyWorks.  You can also look at VB5's callback functionality.  However, if these topics are too advanced, then you should consider utilizing a third-party printer control such as those offered by Videosoft and others.


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now