有没有办法编写一些可以与打印机“对话”的代码,以获得有关其状态的一些基本信息?我真正感兴趣的是查明是否缺纸或卡纸——诸如此类的事情。我应该使用 System.Management 库来处理此类内容吗?
PS - 了解如何获取已在特定 PC 上设置的所有打印机也会很方便。你会怎么做呢?
使用 System.Management 从打印机获取信息相对容易。
//Declare WMI Variables
ManagementObject MgmtObject;
ManagementObjectCollection MgmtCollection;
ManagementObjectSearcher MgmtSearcher;
//Perform the search for printers and return the listing as a collection
MgmtSearcher = new ManagementObjectSearcher("Select * from Win32_Printer");
MgmtCollection = MgmtSearcher.Get();
foreach (ManagementObject objWMI in MgmtCollection)
{
//Do whatever action you want with the Printer
}
Look at http://msdn.microsoft.com/en-us/library/aa394363.aspx有关 Win32_Printer 的方法和属性。对于你的问题:
//Test whether a Win32_Printer is out of paper or jammed
int state = Int32.Parse(objWMI["PrinterState"]);
if (state == 4) {
//Paper Jam
} else if (state == 5) {
//Paper Out
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)