How to get all network printers in asp.net 4.0

2019-05-28 17:29发布

Please any one help me to get all network printers. I get all printers installed in the local machine using "System.Drawing.Printing.PrinterSettings.InstalledPrinters".

But I can't get the printers which are in the Network. I try with "ManagementObjectSearcher" but I can't access this class. I think it does not support in framework 4.0.

I'm using ASP.NET 4.0, C#. Any help will be greatly appreciated.

Thanks Singaravelu.R.

标签: c# asp.net wmi
1条回答
Ridiculous、
2楼-- · 2019-05-28 17:59

if you cannot find/reference the ManagementObjectSearcher Class probably is because you did not add the proper reference to: System.Management.dll to your C# project. Surely it is supported also by .NET 4.

as you can see in this question: ManagementObjectSearcher select network printers? you can find all network printers in this way:

var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Printer");
var results = searcher.Get();

IList<ManagementBaseObject> printers = new List<ManagementBaseObject>();

foreach (var printer in results) {
    if ((bool)printer["Network"]) {
        printers.Add(printer);
    }
}
查看更多
登录 后发表回答