如何判断打印机是否缺纸????????? 最好有具体的实现代码

解决方案 »

  1.   

    http://community.csdn.net/Expert/TopicView3.asp?id=3925038
      

  2.   

    转贴,忘记是谁的了:
    '引用windows scripting host object model
    'Check Printers at 5 minutes intervals
     Private Sub BKWait(HowManySecs)
    '   pause for HowManySecs seconds
        Dim EndWait
        EndWait = DateAdd("s", HowManySecs, Now)
        While Now < EndWait
        Wend
    End Sub
    Sub PrintMon(host As String)
    Dim WScript As New IWshShell_Class
    Dim i As Integer
    Set c = GetObject("WinNT://" & host & ",computer")
    c.Filter = Array("PrintQueue")
    MsgBox "Check Printers on " & host
    For Each pq In c
    If pq.Status > 0 Then CheckPrinter (pq)
    Next
    BKWait (180) '延时3分钟
    DoEvents
    Call PrintMon(host)
    End Sub
    'Display Printer status for non-normal conditions
    Sub CheckPrinter(obj)
    MsgBox "Print  Queue  Name: " & obj.Name
    MsgBox "Printer Model:" & obj.model
    MsgBox "Printer Location:" & obj.Location
    Select Case obj.Status
    Case 1
    MsgBox "打印队列暂停."
    Case 2
    MsgBox "打印队列被删除."
    Case 3
    MsgBox "打印机错误."
    Case 4
    MsgBox "纸堵塞在打印机中."
    Case 5
    MsgBox "打印机缺纸."
    Case 6
    MsgBox "打印机设置为手工进纸."
    Case 7
    MsgBox "打印机错误."
    Case 8
    MsgBox "打印机下线."
    Case 256
    MsgBox "打印机I/O活动."
    Case 512
    MsgBox "打印机忙."
    Case 1024
    MsgBox "打印机正在打印."
    Case 2048
    MsgBox "打印机输出盒满."
    Case 4096
    MsgBox "打印机不可用."
    MsgBox 8192
    MsgBox "打印机等待."
    Case 16384
    MsgBox "打印机正在处理."
    Case 32768
    MsgBox "打印机正在初始化."
    Case 65536
    MsgBox "打印机正在加热."
    Case 131072
    MsgBox "Printer is low on toner."
    Case 262144
    MsgBox "Printer is out of toner."
    Case 524288
    MsgBox "打印机纸未接上."
    Case 1048576
    MsgBox "用户干预打印机."
    Case 2097152
    MsgBox "打印机内存用尽."
    Case 4194304
    MsgBox "打印机仓门打开."
    Case 8388608
    MsgBox "打印机未知错误."
    Case 16777216
    MsgBox "打印机处于省电模式."
    Case Else
    MsgBox "Printer is changing states or has error."
    MsgBox "Status:" & CStr(pq.Status)
    End Select
    End Sub
    Private Sub Form_Load()
    Dim host As String
    label: host = InputBox("请输入打印机服务器所在组(域)名:(eg:3623/lysra)", "=====Printer Monitor=====")
    If host = "" Then GoTo labelCall PrintMon(host)
    End Sub
    '假设3623工作组中LySra为打印机服务器
      

  3.   

    http://support.microsoft.com/kb/q160129/How To Get the Status of a Printer and a Print Job下面函数的:PRINTER_STATUS_PAPER_OUT BOOL GetJobs(HANDLE hPrinter,        /* Handle to the printer. */                JOB_INFO_2 **ppJobInfo, /* Pointer to be filled.  */
                    int *pcJobs,            /* Count of jobs filled.  */
                    DWORD *pStatus)         /* Print Queue status.    */   {   DWORD               cByteNeeded,
                            nReturned,
                            cByteUsed;
        JOB_INFO_2          *pJobStorage = NULL;
        PRINTER_INFO_2       *pPrinterInfo = NULL;   /* Get the buffer size needed. */
           if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))
           {
               if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
                   return FALSE;
           }       pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
           if (!(pPrinterInfo))
               /* Failure to allocate memory. */
               return FALSE;       /* Get the printer information. */
           if (!GetPrinter(hPrinter,
                   2,
                   (LPSTR)pPrinterInfo,
                   cByteNeeded,
                   &cByteUsed))
           {
               /* Failure to access the printer. */
               free(pPrinterInfo);
               pPrinterInfo = NULL;
               return FALSE;
           }       /* Get job storage space. */
           if (!EnumJobs(hPrinter,
                   0,
                   pPrinterInfo->cJobs,
                   2,
                   NULL,
                   0,
                   (LPDWORD)&cByteNeeded,
                   (LPDWORD)&nReturned))
           {
               if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
               {
                   free(pPrinterInfo);
                   pPrinterInfo = NULL;
                   return FALSE;
               }
           }       pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);
           if (!pJobStorage)
           {
               /* Failure to allocate Job storage space. */
               free(pPrinterInfo);
               pPrinterInfo = NULL;
               return FALSE;
           }       ZeroMemory(pJobStorage, cByteNeeded);       /* Get the list of jobs. */
           if (!EnumJobs(hPrinter,
                   0,
                   pPrinterInfo->cJobs,
                   2,
                   (LPBYTE)pJobStorage,
                   cByteNeeded,
                   (LPDWORD)&cByteUsed,
                   (LPDWORD)&nReturned))
           {
               free(pPrinterInfo);
               free(pJobStorage);
               pJobStorage = NULL;
               pPrinterInfo = NULL;
               return FALSE;
           }       /*
            *  Return the information.
            */
           *pcJobs = nReturned;
           *pStatus = pPrinterInfo->Status;
           *ppJobInfo = pJobStorage;
           free(pPrinterInfo);       return TRUE;   }   BOOL IsPrinterError(HANDLE hPrinter)
       {       JOB_INFO_2  *pJobs;
           int         cJobs,
                       i;
           DWORD       dwPrinterStatus;       /*
            *  Get the state information for the Printer Queue and
            *  the jobs in the Printer Queue.
            */
           if (!GetJobs(hPrinter, &pJobs, &cJobs, &dwPrinterStatus))
    return FALSE;       /*
            *  If the Printer reports an error, believe it.
            */
           if (dwPrinterStatus &
               (PRINTER_STATUS_ERROR |
               PRINTER_STATUS_PAPER_JAM |
               PRINTER_STATUS_PAPER_OUT |
               PRINTER_STATUS_PAPER_PROBLEM |
               PRINTER_STATUS_OUTPUT_BIN_FULL |
               PRINTER_STATUS_NOT_AVAILABLE |
               PRINTER_STATUS_NO_TONER |
               PRINTER_STATUS_OUT_OF_MEMORY |
               PRINTER_STATUS_OFFLINE |
               PRINTER_STATUS_DOOR_OPEN))
           {
               free( pJobs );
               return TRUE;
           }       /*
            *  Find the Job in the Queue that is printing.
            */
           for (i=0; i < cJobs; i++)
           {
               if (pJobs[i].Status & JOB_STATUS_PRINTING)
               {
                   /*
                    *  If the job is in an error state,
                    *  report an error for the printer.
                    *  Code could be inserted here to
                    *  attempt an interpretation of the
                    *  pStatus member as well.
                    */
                   if (pJobs[i].Status &
                       (JOB_STATUS_ERROR |
                       JOB_STATUS_OFFLINE |
                       JOB_STATUS_PAPEROUT |
                       JOB_STATUS_BLOCKED_DEVQ))
                   {
                       free( pJobs );
                       return TRUE;
                   }
               }
           }       /*
            *  No error condition.
            */
           free( pJobs );
           return FALSE;   }