我正在尝试获取打印机的信息。使用 WMI 我可以检索一些信息,但前提是已发送作业。
在发送作业之前,我需要检查我的打印机是否缺纸。
这可能吗?
我自己没有使用过,但请看这里:
http://msdn.microsoft.com/en-us/library/system.printing.printqueue.isoutofpaper.aspx
检查 DetectedErrorState 属性,3 为缺纸,4 为无纸,5 为碳粉不足
我就是这样做的...
//check PAPER OK and Toner OK
private static bool IspaperOK(ManagementBaseObject printer)
{
bool PaperOK = true;
string[] printers = ConfigurationManager.AppSettings["ModelliStampanti"].Trim().Split('#');
foreach (var property in printer.Properties)
{
if (property.Name == "DeviceID")
{
var PaperStatus = printer.Properties["PrinterState"].Value.ToString();
for (int i = 0; i <= printers.Length - 1; i++)
{
if (property.Value.ToString() == printers[i].ToString())
{ //131072 = Toner Low
//1024 = printing
//16 = Out of Paper
//5 = out of paper
//128 - offline(no internet connection)
//this is for out of paper....
if ((PaperStatus == "5") ||(PaperStatus == "16"))
{
PaperOK = false;
}
//this is for low toner....
if (PaperStatus == "131072")
{
PaperOK = false;
}
}
}
}
}
return PaperOK;
}
要验证这些问题,请使用这些值而不是 MSDN 中描述的值
//131072 = Toner Low
//1024 = printing
//16 = Out of Paper
//5 = out of paper
//128 - offline(no internet connection OR printer turned off )