How to get the list of all printers in computer

前端 未结 6 1068
长发绾君心
长发绾君心 2020-11-29 17:58

I need to get the list of all printers that connect to computer?

How I can do it in C#, WinForms?

6条回答
  •  無奈伤痛
    2020-11-29 18:43

    If you need more information than just the name of the printer you can use the System.Management API to query them:

    var printerQuery = new ManagementObjectSearcher("SELECT * from Win32_Printer");
    foreach (var printer in printerQuery.Get())
    {
        var name = printer.GetPropertyValue("Name");
        var status = printer.GetPropertyValue("Status");
        var isDefault = printer.GetPropertyValue("Default");
        var isNetworkPrinter = printer.GetPropertyValue("Network");
    
        Console.WriteLine("{0} (Status: {1}, Default: {2}, Network: {3}", 
                    name, status, isDefault, isNetworkPrinter);
    }
    

提交回复
热议问题