运行以下代码,我对“可用性”一无所获。 如果打印机是在线还是离线,如何获取信息?在Windows设置中,但我的代码未显示它:
{
ManagementScope scope = new ManagementScope(@"\root\cimv2");
scope.Connect();
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
foreach (ManagementObject printer in searcher.Get())
{
string printerName = printer["Name"].ToString().ToLower();
Console.WriteLine("Printer :" + printerName);
PrintProps(printer, "Caption");
PrintProps(printer, "ExtendedPrinterStatus");
PrintProps(printer, "Availability");
PrintProps(printer, "Default");
PrintProps(printer, "DetectedErrorState");
PrintProps(printer, "ExtendedDetectedErrorState");
PrintProps(printer, "ExtendedPrinterStatus");
PrintProps(printer, "LastErrorCode");
PrintProps(printer, "PrinterState");
PrintProps(printer, "PrinterStatus");
PrintProps(printer, "Status");
PrintProps(printer, "WorkOffline");
PrintProps(printer, "Local");
}
}
static void PrintProps(ManagementObject o, string prop)
{
try { Console.WriteLine(prop + "|" + o[prop]); }
catch (Exception e) { Console.Write(e.ToString()); }
}
答案 0 :(得分:0)
我遇到的问题是必须区分网络/无线连接的打印机和USB有线打印机:
PrintProps(printer, "WorkOffline"); // works only for usb wired printers