vb.net确定打印机是否脱机/断开连接

时间:2015-12-17 21:47:59

标签: printing vb.net-2010 offline

所以到目前为止我已经尝试了各种各样的东西。我不太确定我是否应该寻找'打印机离线'或队列离线。

使用下面我能够返回默认队列和队列的所有各种属性。但当我拔掉usb打印机(或将其设置为'离线使用')时,我从未看到.IsOffline属性发生变化。

  Dim myDefaultQueue As PrintQueue = Nothing

    Dim localPrintServer As New LocalPrintServer()
    ' Retrieving collection of local printer on user machine
    myDefaultQueue = localPrintServer.GetDefaultPrintQueue

    myDefaultQueue.Refresh()

    If myDefaultQueue.IsOffline Then

        MsgBox("Your printer is offline")

    End If

这个例子就是我一直在做的事情

https://msdn.microsoft.com/library/aa970685(v=vs.100).aspx

1 个答案:

答案 0 :(得分:0)

这似乎是查找打印机是否“离线”的最佳方法。 <或者

How to get Printer Info in .NET?

string printerName = "YourPrinterName";
string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '% {0}'", printerName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection coll = searcher.Get();

foreach (ManagementObject printer in coll)
{
foreach (PropertyData property in printer.Properties)
{
    Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
}

}

相关问题