在与打印机 [英] Talking to a printer

查看:119
本文介绍了在与打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有写一些代码,可以说话到打印机,以获得一些基本信息有关其状态的方法吗?什么我做真正感兴趣的是找出它是否缺纸或卡纸 - 这种性质的东西。 ?我应该使用System.Management库这种类型的东西。

Is there a way to write some code that can 'talk' to printer in order to get some basic info about it's status? What I'm really interested in doing is finding out if it has run out of paper or has a paper jam - things of that nature. Should I use System.Management library for this type of stuff?

PS - 这也将是很方便的知道如何让已设置的所有打印机的举行了一个特定的个人电脑上。你会如何呢?

PS - It would also be handy to know how to get a hold of all the printers that have been set up on a particular PC. How would you go about that?

推荐答案

使用System.Management是比较容易的从打印机获取信息。

Getting information from Printers using System.Management is relatively easy.

    //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
    }

的http:// msdn.microsoft.com/en-us/library/aa394363.aspx 的方法和Win32_Printer的性能。对于你的问题:

Look at http://msdn.microsoft.com/en-us/library/aa394363.aspx for methods and properties of Win32_Printer. For your question:

//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
}

这篇关于在与打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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