当我尝试获取所有打印机并通过以下方式迭代它们时:
Dim printServer As New PrintServer()
For Each printer As PrintQueue In printServer.GetPrintQueues({EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections})
...
Next
看起来它的工作正常只有返回的打印机的UserPrintTicket不正确。如果我在打印机设置中以横向模式设置打印机并使用此方法,则我的printer.UserPrintTicket仍处于纵向模式。
但如果我这样做,那就是抓住了:
printServer.GetPrintQueue(printerName)
然后我的UserPrintTicket是正确的。我会使用这个,但我似乎无法找到如何使用此功能访问网络打印机(我尝试了几种方法来获取它,没有运气)。
所以这是我的两个问题:
答案 0 :(得分:2)
好的,我昨天大部分时间都试图解决这个问题,今天早上我终于找到了解决方案。我仍然不知道为什么1)UserPrintTicket在GetPrintQueues和GetPrintQueue之间有所不同,但要列出我的所有打印机并为每个打印机获取正确的UserPrintTicket,您需要在打印机的HostingPrintServer上调用GetPrintQueue。工作。换句话说:
Dim printServer As New PrintServer()
For Each printer As PrintQueue In printServer.GetPrintQueues({EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections})
'Get the parent PrintServer and uses it to get the PrintQueue, seems like overkill but that's the only way I found to get the correct UserPrintTicket
Dim currentPrinter As PrintQueue = printer.HostingPrintServer.GetPrintQueue(printer.Name)
...
Next
希望有人帮助!