473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Not possible to get printer status with c#.net?

I am told by an experienced c#.net programmer that it is not possible
to get the code to get a printers status. I've been hammering on this
for a week and have combed through hp's web sites and google and
microsoft...nothing for c#. If anyone has a solution, I would
appreciate knowing.
Thanks,
Trint

Nov 16 '05 #1
7 28733
This is a function for a printer driver. When you print to a spooler it is
not relevant whether the printer hardware is ready or not.

If you are bypassing the spooler and going direct to hardware for some
reason, then you are probably talking about a Win32 API call that you would
make from C# via P/Invoke.

--Bob

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am told by an experienced c#.net programmer that it is not possible
to get the code to get a printers status. I've been hammering on this
for a week and have combed through hp's web sites and google and
microsoft...nothing for c#. If anyone has a solution, I would
appreciate knowing.
Thanks,
Trint

Nov 16 '05 #2
In general the printer status can be queried using System.Management and
WMI.

Willy.

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am told by an experienced c#.net programmer that it is not possible
to get the code to get a printers status. I've been hammering on this
for a week and have combed through hp's web sites and google and
microsoft...nothing for c#. If anyone has a solution, I would
appreciate knowing.
Thanks,
Trint

Nov 16 '05 #3

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am told by an experienced c#.net programmer that it is not possible
to get the code to get a printers status. I've been hammering on this
for a week and have combed through hp's web sites and google and
microsoft...nothing for c#. If anyone has a solution, I would
appreciate knowing.
Thanks,
Trint

Here is how:

using System;
using System.Management;
enum PrinterStatus {
Other = 1,
Unknown,
Idle,
Printing,
Warmup,
Stopped,
printing,
Offline
}

public class Wmis {
public static void Main() {
PrinterStatus stat;
if ((stat = GetPrinterStat("\\\\server\\printername")) != 0) // UNC or a
local name
{
Console.WriteLine(stat);
}
else
Console.WriteLine("Failed to get status");
}
static PrinterStatus GetPrinterStat(string printerDevice)
{
PrinterStatus ret = 0;
string path = "win32_printer.DeviceId='" + printerDevice + "'";
using (ManagementObject printer = new ManagementObject(path))
{
printer.Get();
PropertyDataCollection printerProperties = printer.Properties;
PrinterStatus st =
(PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
ret = st;
}
return ret;
}
}
Willy.
Nov 16 '05 #4
I will try this...
Thanks,
Trint

Nov 16 '05 #5
Willy,
How can I make listBox1 visible? I changed your code slightly from:
if ((stat = GetPrinterStat("\\\\server\\printername")) != 0)
{
Console.WriteLine(stat);
}
To:
{
Form1.listBox1.Items.Add(stat);
}
so that I can get the error messages back in windows, but I get this
error message at compile:
'GetPrinterStatus1.Form1.listBox1' is inaccessible due to its
protection level
How do I change the listBox's protection level?
Thanks,
Trint

Nov 16 '05 #6
Ok,
Here is the fix to make it work in Windows:

public class Form1 : System.Windows.Forms.Form
{
....
protected System.Windows.Forms.ListBox listBox1;
....
....
public class Wmis: Form1
{
....
....
Wmis f1 = new Wmis();
f1.listBox1.Items.Add(stat);

The only thing is, I wish that I could get error codes like 'tray 2
empty' or 'tray 3 empty' or 'out of toner'.
Any suggestions?
Thanks,
Trint


trint wrote:
Willy,
How can I make listBox1 visible? I changed your code slightly from:
if ((stat = GetPrinterStat("\\\\server\\printername")) != 0)
{
Console.WriteLine(stat);
}
To:
{
Form1.listBox1.Items.Add(stat);
}
so that I can get the error messages back in windows, but I get this
error message at compile:
'GetPrinterStatus1.Form1.listBox1' is inaccessible due to its
protection level
How do I change the listBox's protection level?
Thanks,
Trint


Nov 16 '05 #7
Check the WMI info in MSDN. The class to search for is win32_printer.
Some printer manufactures supply printer drivers that fill the
ExtendedPrinterStatus, DetectErrorState and ExtendedDetectErrorState
property, some don't care at all about WMI.

Willy.
"trint" <tr***********@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
Ok,
Here is the fix to make it work in Windows:

public class Form1 : System.Windows.Forms.Form
{
...
protected System.Windows.Forms.ListBox listBox1;
...
...
public class Wmis: Form1
{
...
...
Wmis f1 = new Wmis();
f1.listBox1.Items.Add(stat);

The only thing is, I wish that I could get error codes like 'tray 2
empty' or 'tray 3 empty' or 'out of toner'.
Any suggestions?
Thanks,
Trint


trint wrote:
Willy,
How can I make listBox1 visible? I changed your code slightly from:
if ((stat = GetPrinterStat("\\\\server\\printername")) != 0)
{
Console.WriteLine(stat);
}
To:
{
Form1.listBox1.Items.Add(stat);
}
so that I can get the error messages back in windows, but I get this
error message at compile:
'GetPrinterStatus1.Form1.listBox1' is inaccessible due to its
protection level
How do I change the listBox's protection level?
Thanks,
Trint

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jim Warner | last post by:
I am having problems using Borland 5.02 C/C++ for testing printer status repeatly. I wish to use my printer to detect off-line, removing paper, and so on with my software. I have tried using...
0
by: Gordon Truslove | last post by:
I've been trying to get the printer status using GetPrinter and Printer_Info_2 I'm getting closer, but it still fails. Error 122 - The data area passed to a system call is too small. ...
3
by: Gordon Truslove | last post by:
I've been trying to get the printer status using GetPrinter and Printer_Info_2 I'm getting closer, but it still fails. Error 122 - The data area passed to a system call is too small....
0
by: cortukmehmet | last post by:
I wrote this code to check the status of printer.But it says "Unknown" as printer. /////////////////////////////////////////////////////////////////////////////...
1
by: Vanessa | last post by:
Hi, I'm trying to select a printer in the system printers collection. I'm able to do this. However, if the printer is a network printer and happens that this printer is not on or not ready, I...
6
by: Pipo | last post by:
Hi, Does anyone know how I can read out the printer status? I want to sent a bulk of documents to the printer (or 1 by 1) but if something goes wrong e.g. out of paper, cartridge empty, tray...
2
by: TARUN | last post by:
Hello all, Please help and suggest the code to get the printer status over the network. for Example, i have an string "\\\\os1\\PtName" where os1 is the system name and PtName is the printer...
9
by: id10t error | last post by:
Hello, I am going to be using a Symbol WT4090 to scan items. I need to printer a tag from the Zebra ql320 plus. I am trying to do this is Visual basic 2005. Does anyone know and good site to...
1
by: Steve | last post by:
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.