Go: Get the current state of the printer in C #

Source: Internet
Author: User

Ext: http://blog.csdn.net/lijipan/archive/2005/04/18/352678.aspx

To obtain the status of a printer, you should define a union.

Enum Printerstatus
{
Other states = 1,
Unknown
Free
is printing,
Preheating
Stop printing,
In print,
Offline
}

"Printing" and "printing" are the same meaning, as to why it is so, not yet known.

Add a system.management reference to the program: using System.Management;

Then write the function to get the printer status as follows:

<summary>
Get the current state of the printer
</summary>
<param name= "Printerdevice" > Printer device name </param>
<returns> Printer Status </returns>
Private Printerstatus Getprinterstat (string printerdevice)
{
Printerstatus ret=0;
String path=@ "Win32_Printer. Deviceid= ' "+printerdevice+" ";
ManagementObject printer=new ManagementObject (path);
Printer. Get ();
ret= (Printerstatus) Convert.ToInt32 (printer. properties["Printerstatus"]. Value);
return ret;
}

Call Example:

MessageBox.Show (Getprinterstat ("////192.168.0.88//samsung scx-4x16 Series"). ToString ());

trackback:http://tb.blog.csdn.net/trackback.aspx?postid=352678

Added: System.Windows.Forms.MessageBox.Show (printer. properties["WorkOffline"]. Value.tostring ());

You can obtain whether the printer is offline.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.