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

x
?
Solved

PRINTER_STATUS_OFFLINE condition not detected by GetPrinter or FindFirstPrinterChangeNotification

Posted on 2004-09-04
2
Medium Priority
?
1,353 Views
Last Modified: 2013-12-03
I have written a small printer monitor that updates a list of connected printers with the status information of the printer. The application uses a seperate thread that executes the FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification calls to get printer change notifications. The problem I am having is that when a printer is set to offline, although a notification is being generated and picked up by the monitoring thread, the PRINTER_NOTIFY_INFO_DATA.NotifyData.awData[0] = 0 for Type = PRINTER_NOTIFY_TYPE and Field = PRINTER_NOTIFY_FIELD_STATUS instead of having the 0x80 bit set (PRINTER_STATUS_OFFLINE). A call to GetPrinter ( hPrinter, 2, pBuf ...) returns a PRINT_INFO_2 structure that has the Status field also set to 0.

When the code first runs it initialises by calling the GetPrinter API call for each connected printer and sets the status for each printer based on the value of the Status field in the PRINT_INFO_2 structure.

The code works fine for other notifications such as pausing the printer - the status field has the 0x01 bit set.

Any ideas?

Here is some simple sample code. When compiled this app takes a printer name on the command line in the form \\server\printername. It then prints out the current status value of the printer. To test: connect the test machine to a network printer. Make sure the printer is functioning correctly. Run the application - a status of 0 should be printed. Now pause the printer by righ clicking the printer and select pause printing. Run the application again - a status of 1 should be printed. Set printing to resume and then set the printer to Use Offline. Run the application again. A status of 128 (0x80) should be reported but instead it reports 0.

#include "windows.h"
#include "winspool.h"
#include "stdio.h"

int main(int argc, char* argv[])
{
  HANDLE hPrinter ;
  PRINTER_DEFAULTS pd ;
  PRINTER_INFO_2 * pBuf ;
  DWORD dwBytesNeeded ;

  memset ( &pd, 0, sizeof ( pd ) ) ;
  pd.DesiredAccess = PRINTER_ALL_ACCESS ;

  if ( OpenPrinter ( argv[1], &hPrinter, &pd ) )
  {
    GetPrinter ( hPrinter, 2, NULL, 0, &dwBytesNeeded ) ;
    if ( GetLastError ( ) == ERROR_INSUFFICIENT_BUFFER )
    {
      if (  ( pBuf = (PRINTER_INFO_2 * ) malloc ( dwBytesNeeded ) ) )
      {
        if ( GetPrinter ( hPrinter, 2, ( LPBYTE ) pBuf, dwBytesNeeded, &dwBytesNeeded ) )
        {
          printf ( "Status for printer %s is [%d]\n", argv[1], pBuf->Status ) ;
        }
        else
        {
          printf ( "Error: [%ld]\n", GetLastError ( ) ) ;
        }

        free ( pBuf ) ;
      }

    }

    ClosePrinter ( hPrinter ) ;
  }

  return 0;
}
0
Comment
Question by:Julian Hansen
[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 Comments
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 0 total points
ID: 11980773
Ok, I have solved this one - looked through the PAQ and got an idea from there.

Aparently the OFFLINE status is reserved for mechanical problems not for instances where an administrator has set the printer to offline.

To discover if the printer has been set to offline you have to check the Attributes member of the PRINTER_INFO_2 structure for the the PRINTER_ATTRIBUTE_WORK_OFFLINE bit.
0
 

Expert Comment

by:ee_ai_construct
ID: 11981157
Closed, 250 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Moderator
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

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