0

If I look up a printer in Active Directory, is there any way to determine the server it is installed on? If I look up the printer in the Active Direcory console, the properties caption tells me the server, how can I determine this value programatically?

Edit: Language is C#

Charles
  • 50,943
  • 13
  • 104
  • 142
Jeremy
  • 44,950
  • 68
  • 206
  • 332

3 Answers3

2

The serverName attribute or uncName attribute of the printQueue object in AD is likely what you want.

Brian Desmond
  • 4,473
  • 1
  • 13
  • 11
1

To build on the answer in the link alexn provided, here's a program I wrote that will print out the server information for every printer on a computer:

        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);
                    }
                }
            }
        }

All the other properties of the printer are available as PropertyData as well.

Jim
  • 833
  • 6
  • 13
0

To find a shared printer, click Desktop, double-click Network, double-click the name of the computer to which the printer is attached, and then double-click the printer that you want to list in the Windows SBS Console.

Aaron Zeng
  • 16
  • 2