如何获得在.NET打印机信息? [英] How to get Printer Info in .NET?
本文介绍了如何获得在.NET打印机信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在标准PrintDialog类有四个与选定的打印机相关的值:状态,类型,位置,并注释
In the standard PrintDialog there are four values associated with a selected printer: Status, Type, Where, and Comment.
如果我知道打印机的名称,我怎么能在C#2.0中获取这些值?
If I know a printer's name, how can I get these values in C# 2.0?
推荐答案
作为的 dowski建议,您可以使用WMI来获取打印机属性。下面code上显示为一个给定的打印机名称的所有属性。其中,你会发现:PrinterStatus,评论,位置,DriverName的,端口名称等
As dowski suggested, you could use WMI to get printer properties. The following code displays all properties for a given printer name. Among them you will find: PrinterStatus, Comment, Location, DriverName, PortName, etc.
using System.Management;
...
string printerName = "YourPrinterName";
string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection coll = searcher.Get();
foreach (ManagementObject printer in coll)
{
foreach (PropertyData property in printer.Properties)
{
Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));
}
}
这篇关于如何获得在.NET打印机信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文