如果我在Active Directory中查找打印机,有没有办法确定安装它的服务器?如果我在Active Direcory控制台中查找打印机,属性标题告诉我服务器,如何以编程方式确定此值?
编辑:语言是C#
答案 0 :(得分:2)
AD中printQueue对象的serverName
属性或uncName
属性可能就是您想要的。
答案 1 :(得分:1)
要建立在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。
答案 2 :(得分:0)
要查找共享打印机,请单击“桌面”,双击“网络”,双击打印机所连接的计算机的名称,然后双击要在Windows SBS Console中列出的打印机。