
Signature
Jason Newell, MCAD
Software Engineer
using System;
using System.Management;
namespace PrinterTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select
* from Win32_Printer");
foreach (ManagementObject printer in searcher.Get())
{
string message = (string)printer["Name"] + ": Printer Status = ";
/* PrinterState is obsolete! */
switch ((UInt16)printer["PrinterStatus"])
{
case 1:
message += " Other";
break;
case 2:
message += " Unknown";
break;
case 3:
message += " Idle";
break;
case 4:
message += " Printing";
break;
case 5:
message += " Warmup";
break;
case 6:
message += " Stopped printing";
break;
case 7:
message += " Offline";
break;
default:
message += " ERROR - Constant not defined";
break;
}
Console.WriteLine(message);
}
Console.In.Read();
}
}
}
> Has anyone actually used this and could help me out. I've got plenty of
> guesses about it - i need to find out what these represent and if WIM
[quoted text clipped - 50 lines]
> > >
> > > Harry
BTW,
If that's not good enough, the same thing can be easily accomplished
using OpenPrinter(), GetPrinter(), ClosePrinter() Win32 methods. If you
need an example, let me know what language you want it in and I can send you
an example.

Signature
Jason Newell, MCAD
Software Engineer
> Harry,
> The following code works on my machine. I used the following url as a
> guide.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win3
2_printer.asp
> > Has anyone actually used this and could help me out. I've got plenty of
> > guesses about it - i need to find out what these represent and if WIM
[quoted text clipped - 51 lines]
> > > >
> > > > Harry
Harry Simpson - 03 Aug 2004 16:50 GMT
Jason,
I used your code in a C# project and, yes, it "works" just like my code
"works". Where it doesn't work is if you pause the printer, turn of the
printer, throw the printer out the window, - the PrinterStatus remains 3 or
"Idle" instead of showing the true state of the printer.
We were using the API calls to the winspool.drv and that code did seem to
work accurately, but it's unmanged code within managed code. Ever so often,
the unmanged code would crash and bring down the whole app.
Really appreciate your time on this Jason!
Harry
MCSD
PS. VB.NET is code of choice.
> BTW,
> If that's not good enough, the same thing can be easily accomplished
[quoted text clipped - 5 lines]
> > The following code works on my machine. I used the following url as a
> > guide.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win3
2_printer.asp
> ManagementObjectSearcher("Select
> > * from Win32_Printer");
[quoted text clipped - 98 lines]
> > > > >
> > > > > Harry
Fernando Hunth - 26 Aug 2004 20:14 GMT
Harry :
Have you solved it ?
rsk7485 - 30 Jul 2007 13:20 GMT
Hi,
I am having same problem with printer status.
can i get the detailed code for retreiving printer status problem??
I am being working in that sinve a week and i am not getting the correct
result.
I will be very thankful for you...
Please...
Rahul Kadu
>Jason,
>
[quoted text clipped - 26 lines]
>> > > > >
>> > > > > Harry