By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,362 Members | 1,747 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,362 IT Pros & Developers. It's quick & easy.

Detect if windows printer not responding

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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'
http://support.microsoft.com/kb/160129/en-us

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.Management
assembly to your project.

Imports System.Management

Dim oq As New.ObjectQuery("SELECT * FROM Win32_PrintJob") '
Dim query1 As New ManagementObjectSearcher(oq)
Dim queryCollection1 As ManagementObjectCollection = query1.Get()
Dim mo As Management.ManagementObject
For Each mo In queryCollection1
Console.WriteLine(("Printer Driver : " + mo("DriverName").ToString()))
Console.WriteLine(("Document Name : " + mo("Document").ToString()))
Console.WriteLine(("Document Owner : " + mo("Owner").ToString()))

If (mo("JobStatus") IsNot Nothing) Then
Console.WriteLine(("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:
http://msdn.microsoft.com/en-us/libr...82(VS.85).aspx
http://msdn.microsoft.com/en-us/libr...70(VS.85).aspx

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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
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.

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.