Network Printing in C #

I can get a list of network printers through this code:

private void Form1_Load(object sender, EventArgs e)
{
  foreach (String printer in PrinterSettings.InstalledPrinters)
  {
    listBox1.Items.Add(printer.ToString());
  }
}

For each network printer, I want to extract additional information, for example: (a) get information about a document, for example, the number of pages printed, file name, file size, etc.

(b) obtain the computer IP address from which the document was printed.

(c) get the name of the user who printed the document.

How to achieve the above? Any code samples will be appreciated. Should I view Windows Management Instrumentation (WMI) content?

+5
source share
2 answers
+1

, WMI, Win32_Printer, , , (a) , , , , .. (b) IP-, . (c) , .

:

private void button1_Click ( , EventArgs e)       {           string printerName = "Ricoh-L4-1";           string query = string.Format( "SELECT * from Win32_Printer LIKE '% {0}'", _);           ManagementObjectSearcher = ManagementObjectSearcher ();           ManagementObjectCollection coll = searcher.Get();

        foreach (ManagementObject printer in coll)
        {
            foreach (PropertyData property in printer.Properties)
            {
                listBox1.Items.Add(string.Format("{0}: {1}", property.Name, property.Value));
            }
        } 

    }
0

All Articles