Reputation: 17
I have a usb printer. I don't know how to take device id also. I want to take vid/ pid using c# code. Any help appreciated.
Upvotes: 0
Views: 653
Reputation: 127
Have you tried:
using System.Management;
ManagementObjectSearcher myPrinterObject = new ManagementObjectSearcher("select * from Win32_Printer");
foreach (ManagementObject obj in myPrinterObject.Get())
{
Console.WriteLine("Name - " + obj["Name"]);
Console.WriteLine("Network - " + obj["Network"]);
Console.WriteLine("Availability - " + obj["Availability"]);
Console.WriteLine("Is default printer - " + obj["Default"]);
Console.WriteLine("DeviceID - " + obj["DeviceID"]);
Console.WriteLine("Status - " + obj["Status"]);
Console.WriteLine(String.Empty.PadLeft(obj["Name"].ToString().Length, '='));
}
The WMI properties are: https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer?redirectedfrom=MSDN
You can also wrap the manufacturer DLL with a C++ wrapper and then call that from your C# application seamlessly however this will could take you a long time to write!
Upvotes: 1