Win32_Printer

H

Harry Simpson

I'm trying to grab printer status for a printer with WMI

I got a mo("PrinterState").tostring of "128" for a paused HP printer. What
is "128" equate to? It did give a mo("PrinterStatus").tostring of 1 =
"paused" which was correct but it took a while to display the correct state.

When I un-paused the printer, I got a mo("PrinterState").tostring of "0".
What is "0" equate to? It got a mo("PrinterStatus").tostring of 0. Is "0"
mean ok, ready?

Anyone had experience in correctly grabbing info from WMI?

I'm getting info but not consistent info and i don't know how to translate
the codes since they don't match up with the ones in the WMI SDK.


Any clues as how to effectively use
Management.ManagementObjectSearcher("Select * from Win32_Printer")

to get accurate info on networked printers within a domain?



TIA

Harry
 
L

Lebrun Thomas

I got a mo("PrinterState").tostring of "128" for a paused HP printer. What
is "128" equate to?

Maybe it's the memory of your printer ?

What is "0" equate to? It got a mo("PrinterStatus").tostring of 0. Is "0"
mean ok, ready?

I believe.

Bye.
 
H

Harry Simpson

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
actually works or not.

Thanks

Harry
 
J

Jason Newell

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/win32_printer.asp

--
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();
}
}
}
 
J

Jason Newell

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.

--
Jason Newell, MCAD
Software Engineer


Jason Newell said:
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/win32_printer.asp

--
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();
}
}
}

Harry Simpson said:
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
actually works or not.

Thanks

Harry

printer.
What Is
"0" printer.
What
 
H

Harry Simpson

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.
Jason Newell said:
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.

--
Jason Newell, MCAD
Software Engineer


Jason Newell said:
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/win32_printer.asp
--
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();
}
}
}

Harry Simpson said:
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
actually works or not.

Thanks

Harry

I got a mo("PrinterState").tostring of "128" for a paused HP printer.
What
is "128" equate to?

Maybe it's the memory of your printer ?

What is "0" equate to? It got a mo("PrinterStatus").tostring of 0. Is
"0"
mean ok, ready?

I believe.

Bye.

--
LEBRUN Thomas
http://morpheus.developpez.com


I'm trying to grab printer status for a printer with WMI

I got a mo("PrinterState").tostring of "128" for a paused HP printer.
What
is "128" equate to? It did give a mo("PrinterStatus").tostring of
1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top