"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.