开发者

How to get all network printers in asp.net 4.0

开发者 https://www.devze.com 2023-04-08 18:52 出处:网络
Please any one help meto get all network printers. I get all printers installed in the local machine using \"System.Drawing.Printing.PrinterSettings.InstalledPrinters\".

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.


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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号