0

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.

4

1 回答 1

1

你有没有尝试过:

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, '='));
}

WMI 属性是: https ://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer?redirectedfrom=MSDN

您还可以使用 C++ 包装器包装制造商 DLL,然后从您的 C# 应用程序中无缝调用它,但这可能会花费您很长时间来编写!

于 2021-09-18T04:38:44.267 回答