我需要一个不直接打印的打印机列表。获得直接打印的列表似乎相当容易。但如何做到相反呢?
Dim PrintServer As New SysPrint.PrintServer
Dim arrFlags(0) As SysPrint.EnumeratedPrintQueueTypes
arrFlags(0) = System.Printing.EnumeratedPrintQueueTypes.DirectPrinting
Dim QColl As SysPrint.PrintQueueCollection = PrintServer.GetPrintQueues(arrFlags)
PrintServer.GetPrintQueues Method
EnumeratedPrintQueueTypes Enumeration
MSDN表示EnumeratedPrintQueueTypes具有FlagsAttribute属性,该属性允许按位组合其成员值。所以我应该能够以某种方式指定NOT direct。我该怎么做?
我尝试这样做arrFlags(0) = Not System.Printing.EnumeratedPrintQueueTypes.DirectPrinting
但是没有返回任何结果。显然不正确。
那么如何操作flags属性以消除所有直接打印的打印机?
答案 0 :(得分:0)
这是一种方法,但它似乎非常不优雅:
'get full list
Dim PrintServer As New SysPrint.PrintServer
Dim QColl As SysPrint.PrintQueueCollection = PrintServer.GetPrintQueues()
'get those not printing direct
Dim Qcoll2 As List(Of SysPrint.PrintQueue) = QColl.Where(Function(x) Not (x.IsDirect)).ToList
'select name only
Dim strList As List(Of String) = Qcoll2.Select(Function(x) x.Name).ToList