網上打了很多方法都無效,以下方法在WIN7pro中測試可用:
Sub QQ1722187970() MsgBox "當前默認的打印機名稱為" & Excel.Application.ActivePrinter End Sub
通過直接使用WMI來獲取
using System.Management;
string query = string.Format("SELECT * from Win32_Printer "); var searcher = new ManagementObjectSearcher(query); var printers = searcher.Get(); foreach(var printer in printers) { Console.WriteLine(printer.Properties["Name"].Value); foreach(var property in printer.Properties) { Console.WriteLine(string.Format("\t{0}: {1}", property.Name, property.Value)); } Console.WriteLine(); }如此可以得到許多信息,包括狀態、聯機、脫機以及錯誤
其中 (bool)printer.Properties["WorkOffline"].Value 指示打印機是否脫機