Detect if windows printer not responding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    Detect if windows printer not responding

    Hi All

    I am using vb.net 2005 in a windows forms application

    I send data to the selected windows printer using a PrintDocument object

    Is there any way to detect if the Printer is not responding e.g turned off,
    out of paper etc, via code

    I want to display a warning if the printer needs attention rather than just
    keep filling the Printer queue

    Regards
    Steve


  • Linda Liu[MSFT]

    #2
    RE: Detect if windows printer not responding

    Hi Steve,

    The status of printers and print jobs are updated by the Win32 Spooler
    during the de-spool of a print job. All other time, when that printer is
    not de-spooling and reports no state information, the printer is considered
    to be ready and idle. It means that if there's no print job in the print
    queue, we have no way to get the real status of the physical printer.

    To determine the state of a physical printer, there is one fundamental
    premise that must be true: the Spooler must be attempting to send a print
    job to the physical printer. This is the only time the state of the printer
    is reported by the port monitor. In addition, the most meaningful
    information may be reported in the status members of a JOB_INFO structure
    for that particular print job because some port monitor will have set these
    values directly.

    For more information on how to get the status of a printer and a print job,
    you may refer to the following KB article:
    'How to get the status of a printer and a print job'


    Alternatively, we can use WMI to get the status of a print job. WMI allows
    us to retrieve large amount of system information including print jobs
    information using a query-like syntax. To retrieve the print status
    information, we can query the Win32_PrintJob class. The following is a
    sample. It requires that you add a reference to the System.Manageme nt
    assembly to your project.

    Imports System.Manageme nt

    Dim oq As New.ObjectQuery ("SELECT * FROM Win32_PrintJob" ) '
    Dim query1 As New ManagementObjec tSearcher(oq)
    Dim queryCollection 1 As ManagementObjec tCollection = query1.Get()
    Dim mo As Management.Mana gementObject
    For Each mo In queryCollection 1
    Console.WriteLi ne(("Printer Driver : " + mo("DriverName" ).ToString()))
    Console.WriteLi ne(("Document Name : " + mo("Document"). ToString()))
    Console.WriteLi ne(("Document Owner : " + mo("Owner").ToS tring()))

    If (mo("JobStatus" ) IsNot Nothing) Then
    Console.WriteLi ne(("Job Status : " + mo("JobStatus") .ToString()))
    End If
    Next mo

    For more information about WMI and WIN32_PrintJob class, please refer to
    the following MSDN documents:
    Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems.

    Represents a print job generated by a Windows application. Any unit of work generated by the print command of an application that is running on a computer running on a Windows operating system is a descendant or member of this class.


    Hope this helps.
    If you have any question, please feel free to let me know.

    Sincerely,
    Linda Liu
    Microsoft Online Community Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    msdnmg@microsof t.com.

    =============== =============== =============== =====
    Get notification to my posts through email? Please refer to
    Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscripti...t/default.aspx.
    =============== =============== =============== =====
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    Working...