C # traverses the printer installed by the system, using WMI to get all the properties of the printer

Source: Internet
Author: User

A netizen sent a message to ask, C # How to traverse the system has installed all the printers, and get information about each printer, such as: port, name and so on

C # inside, although in the System.Drawing.Printing this namespace, provides some access to the system printer, but, to tell the truth is too weak, to obtain the relevant properties of the printer is basically powerless.

C # inside to get the details of the printer, commonly used in 2 ways:

  1. Using the Windows API
  2. Using WMI

I'm using WMI in this way, because it's a method of class SQL that provides the WMI management information of Windows as a form of a database, which is easier to use

The use of WMI in. NET is placed in the System.Management space, and if you want to use it, you need to add a reference to the System.Management.dll

The specific code is as follows:

String wmisql = "SELECT * from Win32_Printer"; managementobjectcollection printers = new ManagementObjectSearcher (wmisql). Get (); foreach (ManagementObject printer in Printers) {    Propertydatacollection.propertydataenumerator PDE = printer . Properties.getenumerator ();    while (PDE. MoveNext ())    {        MessageBox.Show (PDE). Current.name + ":" + PDE. Current.value);        Displays the property name: The form of the property value    }}

It should be at a glance, hey.

C # traverses the printer installed by the system, using WMI to get all the properties of the printer

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.