由网友(梦里梦你梦离)分享简介:在标准PrintDialog类有四个与选定的打印机相关的值:状态,类型,位置,并注释In the standard PrintDialog there are four values associated with a selected printer: Status, Type, Where, and Commen...
在标准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));
}
}
相关推荐
最新文章