如下图所示,当我尝试检索所有打印机时,我只有 2 台打印机。
有没有办法使用 PowerShell WMI 或 C# 返回所有打印机(以便我可以在 powershell 中翻译它)?
我已经尝试过System.Drawing.Printing.PrinterSettings.InstalledPrinters
(参考how to get the list of all printers in computer - C# Winform
),但也只显示了 2 个条目。
如下图所示,当我尝试检索所有打印机时,我只有 2 台打印机。
有没有办法使用 PowerShell WMI 或 C# 返回所有打印机(以便我可以在 powershell 中翻译它)?
我已经尝试过System.Drawing.Printing.PrinterSettings.InstalledPrinters
(参考how to get the list of all printers in computer - C# Winform
),但也只显示了 2 个条目。
简单地,
foreach (String printer in PrinterSettings.InstalledPrinters)
{
Console.WriteLine(printer.ToString()+Environment.NewLine);
}
通过WMI
public static void AvailablePrinters()
{
oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
oManagementScope.Connect();
SelectQuery oSelectQuery = new SelectQuery();
oSelectQuery.QueryString = @"SELECT Name FROM Win32_Printer";
ManagementObjectSearcher oObjectSearcher =
new ManagementObjectSearcher(oManagementScope, @oSelectQuery);
ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();
foreach (ManagementObject oItem in oObjectCollection)
{
Console.WriteLine("Name : " + oItem["Name"].ToString()+ Environment.NewLine);
}
}
Get-WMIObject -class Win32_Printer -computer $printserver | Select Name,DriverName,PortName