views:

199

answers:

2

I am able to get the list of network printers via 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 out more information like: (a) get document information, like number of pages printed, filename, file-size, etc.

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

(c) get username of who printed the document.

How do I achieve the above? any code samples would be appreciated. Do I have to look into Windows Management Instrumentation(WMI) stuffs?

+1  A: 

You might be able to get out some of the information via WMI:

http://msdn.microsoft.com/en-us/library/Aa394363

If you want more information, and your printers support it, you might be able to use SNMP, here's an article\library that might help you find out how to use that:

http://www.codeproject.com/KB/cs/SNMPDLL.aspx

ho1
A: 

yes, I am able to get all the properties and values from WMI, of Win32_Printer using below code, but I could not retrieve basic information like (a) get document information, like number of pages printed, filename, file-size, etc. (b) get computer IP address from which document was printed. (c) get username of who printed the document.

Code:

private void button1_Click(object sender, EventArgs e) { string printerName = "Ricoh-L4-1"; string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); 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));
            }
        } 

    }