2011-12-28 73 views
0

如果我在Active Directory中查找打印機,是否有任何方法可以確定它安裝的服務器?如果我在Active Direcory控制檯中查找打印機,則屬性標題會告訴我服務器,如何以編程方式確定此值?如何確定打印機安裝在哪個服務器上

編輯:語言是C#

+0

「編程式」編程語言? – Filburt 2011-12-28 18:55:18

+0

Arg!對不起,這將使用C# – Jeremy 2011-12-28 19:04:14

+1

看看這個問題,它應該幫助你。 http://stackoverflow.com/questions/296182/how-to-get-printer-info-in-net – alexn 2011-12-28 19:05:59

回答

2

AD中printQueue對象的serverName屬性或uncName屬性很可能是您想要的。

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使用。

+0

這將需要知道什麼服務器電腦設置。 – Jeremy 2011-12-30 04:03:50

0

要找到共享打印機,請單擊「桌面」,雙擊「網絡」,雙擊打印機所連接的計算機的名稱,然後雙擊要在Windows SBS控制檯中列出的打印機。

相關問題