连接打印机时如何设置动作 [英] how to set Action when printer is connected

查看:72
本文介绍了连接打印机时如何设置动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨成员!


我想知道如果打印机的状态联机,我怎么能开启。显然我正在运行WMI示例代码,我确定状态虽然有时证明是不可靠的。现在,我没有任何打印机连接到
我的电脑,有些人报告他们在线,但传真和OneNote除外。 


以下是查询方式对于可用的打印机。

 var printerInfos = new List< PrinterInfo>(); 

try
{
var searcher = new ManagementObjectSearcher(" root\\CIMV2"," SELECT * FROM Win32_Printer")
{
选项= {UseAmendedQualifiers = true}
};

printerInfos.AddRange(searcher.Get()。OfType< ManagementObject>()。选择(queryObj => new PrinterInfo {PrinterName = queryObj [" Name"]。ToString(),IsOnline = !bool.Parse(queryObj [" WorkOffline"]的ToString()。)}));
}
catch(Exception ex)
{
Send(JsonConvert.SerializeObject(ex.StackTrace,Formatting.Indented));
}

发送(JsonConvert.SerializeObject(printerInfos.Where(x =>!x.PrinterName.Equals(" Fax")&& x.IsOnline == true) ,Formatting.Indented));

然后我将它们打开一个打开的websocket到浏览器中。 



对于所有可用的WMI示例,我只能找到有关打印机状态(连接/未连接)的更可靠数据的示例。 



但是,我想要触发一个事件来通过网络套接字,如果连接,打印机状态现在在线或离线。我如何实现这一目标?

解决方案

您好feiyim,


感谢您在此发帖。


对于您的问题,您希望在打印机状态联机时启动。


以下链接可以帮助您。


https://www.c-sharpcorner.com/article / using-management-objects-to-check-online-printers /


https://www.experts-exchange.com/questions/21033545/how-to-check-if-printer-is-offline-in-C -Net.html


注意:此响应包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。


Microsoft不控制这些网站,也没有测试在这些网站上找到的任何软件或信息;因此,Microsoft不能对在那里找到的任何软件或信息的质量,安全性或适用性做出任何陈述。


使用互联网上的任何软件都存在固有的危险, Microsoft提醒您在从Internet检索任何软件之前确保完全理解风险。


祝您好运,


Jack J Jun。


Hi members!

Am wondering how i could fire off an even when the printer's status comes online. Am apparently running through WMI sample codes where i determine the status although its proving to be unreliable at times. Right now, i dont have any printers connected to my computer and some are reporting that they are online with an exception of Fax and OneNote. 

Here is how am querying for the available printers.

var printerInfos = new List<PrinterInfo>();

            try
            {
                var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer")
                {
                    Options = {UseAmendedQualifiers = true}
                };

                printerInfos.AddRange(searcher.Get().OfType<ManagementObject>().Select(queryObj => new PrinterInfo {PrinterName = queryObj["Name"].ToString(), IsOnline = !bool.Parse(queryObj["WorkOffline"].ToString())}));
            }
            catch (Exception ex)
            {
                Send(JsonConvert.SerializeObject(ex.StackTrace, Formatting.Indented));
            }

            Send(JsonConvert.SerializeObject(printerInfos.Where(x => !x.PrinterName.Equals("Fax") && x.IsOnline == true), Formatting.Indented));

I then push them up an open websocket into a browser. 

With all the available WMI examples, this only is the one i find to give more reliable data about the printer status (connected/not connected). 

But then, i want to fire off an event to pass through the web socket, if connected, that the printer status is now online or offline. How do i achieve that?

解决方案

Hi feiyim,

Thank you for posting here.

For your question, you want to fire off an even when the printer's status comes online.

The following link could help you.

https://www.c-sharpcorner.com/article/using-management-objects-to-check-online-printers/

https://www.experts-exchange.com/questions/21033545/how-to-check-if-printer-is-offline-in-C-Net.html

Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you.

Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

Best regards,

Jack J Jun.


这篇关于连接打印机时如何设置动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆