如何在客户端计算机中检查是否已连接打印机 [英] how to check wheather printer is connected or not in client computer
本文介绍了如何在客户端计算机中检查是否已连接打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在客户端计算机上找到或不连接打印机,
为此我写了代码为
Hi,
I want to find wheather printer is connected or not in client computer,
for this i have written code as
ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Connect();
// Select Printers from WMI Object Collections
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
string printerName = "";
foreach (ManagementObject printer in searcher.Get())
{
printerName = printer["Name"].ToString().ToLower();
if (printerName.Contains("citizen"))
{
// Console.WriteLine("Printer = " + printer["Name"]);
if (printer["WorkOffline"].ToString().ToLower().Equals("true"))
{
// printer is offline by user
// Console.WriteLine("Your Plug-N-Play printer is not connected.");
}
else
{
// printer is not offline
Console.WriteLine("Your Plug-N-Play printer is connected.");
}
}
else
{
}
}
上面的代码给出了我托管代码的服务器的打印机状态,但是我想要客户端pc的打印机状态。
推荐答案
看一下打印机[Local]属性。
如果是真,则是本地打印机,如果不是网络打印机。
Take a look at the printer["Local"] property.
If it is True then is a Local printer, if not is a network printer.
这篇关于如何在客户端计算机中检查是否已连接打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文