寻找与 IP 打印机的直接通信通道
我有一个应用程序,允许用户在打印之前选择打印机。我需要能够使用从 .Net 打印机选择对话框返回的信息,找到一种通过 SNMP 直接与打印机进行通信的方法。我的应用程序的要求之一是,当打印机暂停、卡纸、脱机或缺纸等时,它不会向打印机发送任何打印作业。我只能通过我拥有的打印机类型的 SNMP 获取此信息。
我一直在使用 WMI 查询来获取打印机信息,然后使用该 WMI 查询中的 ShareName 和 ServerName 值派生到该打印机的通信通道。这已经有效了一年多。
最近,这里的网络团队将我的应用程序从 Windows 2003 服务器迁移到 Windows 2008 R2 服务器。当该应用程序位于 2008 年的新主页时,WMI 查询中的 ServerName 和 ShareName 值始终返回为空,从而无法使用我现有的代码直接与打印机进行通信。
是否还有其他人可以仅根据用户从 .Net 打印机选择对话框中选择打印机来直接与打印机进行通信?出于此应用程序的目的,我们可以放心地期望打印机始终具有相同的类型并且始终连接到网络。
这是我一直在使用的 WMI 查询:
"SELECT * from Win32_Printer WHERE Name LIKE '%MyPrinter'"
欣赏它。
I have an application that allows a user to pick a printer before printing. I need to be able to, using information returned from the .Net printer selection dialog, find a way to communicate over SNMP directly with the printer. One of the requirements for my application is that it not send any print jobs to the printer while the printer is paused or jammed or offline or out of paper, etc. I can get this information only via SNMP for the type of printer I have.
I have been using a WMI query to get the printer information, then deriving a communication channel to that printer using the ShareName and ServerName values in that WMI query. This has worked for well over a year.
Recently the network team here moved my application from a Windows 2003 server to a Windows 2008 R2 server. With the application in its new 2008 home, the values for ServerName and ShareName in the WMI query always come back empty making it impossible to communicate directly with the printer using my existing code.
Does anyone else have another way of communicating with printers directly only based on the user selecting a printer from the .Net printer select dialog? For the purposes of this application we are safe to expect the printer to always be of the same type and always be connected to the network.
Here is the WMI query I have been using:
"SELECT * from Win32_Printer WHERE Name LIKE '%MyPrinter'"
Appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与我给 c# 的答案相同:如何使用winspool_drv 监控打印作业
以下是使用Win32_Printer。
文档说 PrinterState 已过时,您应该使用 PrinterStatus,这是不幸的,考虑到 PrinterState 为您提供了您正在寻找的所有状态。
话虽这么说,PrinterState 和 PrinterStatus 应该 返回 >如果打印机不可用,则为 0。
This is the same answer I gave to c# : How to Monitor Print job Using winspool_drv
Here is an example of the using Win32_Printer.
The documentation says that PrinterState is obsolete, and you should use PrinterStatus, that is unfortunate, considering PrinterState gives you all the statuses you are looking for.
That being said, both PrinterState and PrinterStatus should return > 0 if the printer is not available.