打印机服务器的地址在哪个文件夹,如何确定打印机安装在哪个服务器上

要建立在alexn提供的链接的答案,这里有一个程序,我写这将打印出服务器的信息每个打印机的计算机上:

String server = String.Empty;

// For each printer installed on this computer

foreach (string printerName in PrinterSettings.InstalledPrinters) {

// Build a query to find printers named [printerName]

string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName);

// Use the ManagementObjectSearcher class to find Win32_Printer's that meet the criteria we specified in [query]

ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

ManagementObjectCollection coll = searcher.Get();

// For each printer (ManagementObject) found, iterate through all the properties

foreach (ManagementObject printer in coll) {

foreach (PropertyData property in printer.Properties) {

// Get the server (or IP address) from the PortName property of the printer

if (property.Name.Equals("PortName")) {

server = property.Value as String;

Console.WriteLine("Server for " + printerName + " is " + server);

}

}

}

}

打印机的所有其他属性也可以作为PropertyData使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值