So its adding twice the list of properties of the printer to the listbox1 and i want to add it once.
Now i found that when im adding first the list of printers connected to the pc to combobox1 i see like 3-4 printer devices connected even if only one is connected physicaly:
My printer is: HP Officejet 6550 E USB Device.
So i can try to remove the other printer devices manualy and leave only one through the ControlPanel but its not a solution. Since my program is working with usb inseretion/removal events i dont want the user each time he inesrt a printer he will have to remove some devices of it manualy.
So my first problem is how to make that it will show me only once the properties list in the listbox1?
Here is the code im using in the contructor in my project:
I must say also if im doing it with Win32_DiskDrive for example i see the properties only once on any hard disk i have in the pc or any hard disk i have external on usb.
Only on Win32_Printer i have this problem.
The code:
Expand|Select|Wrap|Line Numbers
- private void Form1_Load(object sender, EventArgs e)
- {
- ManagementObjectSearcher mosPrinter = new ManagementObjectSearcher( "SELECT * FROM Win32_Printer");
- foreach (ManagementObject moDprinte in mosPrinter.Get())
- {
- printerName = moDprinte["Name"].ToString().ToLower();
- if (printerName.Equals(@"hp officejet"))
- {
- comboBox1.Items.Add(moDprinte["Name"].ToString());
- }
- foreach (PropertyData p in moDprinte.Properties)
- {
- listBox1.Items.Add(String.Format("{0}: {1}", p.Name, p.Value == null ? "NULL" : p.Value));
- }
- }