2010-03-01 102 views

回答

139

試試這個:

foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) 
{ 
    MessageBox.Show(printer); 
} 
+0

也適用於WPF,不錯! – kjhf 2017-01-25 17:33:30

20

看看靜態System.Drawing.Printing.PrinterSettings.InstalledPrinters屬性。

這是系統中所有已安裝打印機的名稱列表。

+0

應用

private void GetAllPrinterList() { ManagementScope objScope = new ManagementScope(ManagementPath.DefaultPath); //For the local Access objScope.Connect(); SelectQuery selectQuery = new SelectQuery(); selectQuery.QueryString = "Select * from win32_Printer"; ManagementObjectSearcher MOS = new ManagementObjectSearcher(objScope, selectQuery); ManagementObjectCollection MOC = MOS.Get(); foreach (ManagementObject mo in MOC) { lstPrinterList.Items.Add(mo["Name"].ToString()); } } 

Click here to download source and application demo

演示感謝您對MSDN鏈接! – paulsm4 2015-07-19 03:15:02

32

如果你需要比打印機的只是名稱的詳細信息,您可以使用System.Management API來對它們進行查詢:http://www.snippetsource.net/Snippet/96/list-all-installed-printers

:取自

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

3

在ASP.NET中獲取網絡和本地打印機列表

此方法使用Windows Management Instrumentation或WMI接口。這是一種用於獲取有關Windows操作系統上運行的各種系統(硬件)信息的技術。其中列舉的網絡和本地打印機

enter image description here

+0

是你的ASP.NET演示嗎? – AaA 2017-12-22 09:47:31

0
public List<string> InstalledPrinters 
    { 
     get 
     { 
      return (from PrintQueue printer in new LocalPrintServer().GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, 
       EnumeratedPrintQueueTypes.Connections }).ToList() 
        select printer.Name).ToList(); 
     } 
    } 
+0

你可以添加一個解釋來跟隨代碼嗎? – jhpratt 2017-11-25 00:50:01

相關問題