我试图显示服务器上所有可用的打印机名称以及与之关联的托盘数量。如何显示与打印机关联的纸盘数量?
我使用了以下代码。它可以工作,但不能显示与所有信息的通信。我应该包括消息框吗?如何显示所有这些信息?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Printing;
using System.Drawing.Printing;
using System.Management;
namespace Find
{
class Program
{
static void Main(string[] args)
{
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);
}
}
}
}