Jeremy
Jeremy

Reputation: 46322

How to determine what server a printer is installed on

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#

Upvotes: 0

Views: 3944

Answers (3)

Aaron Zeng
Aaron Zeng

Reputation: 16

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.

Upvotes: 0

Brian Desmond
Brian Desmond

Reputation: 4503

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

Upvotes: 2

Jim
Jim

Reputation: 833

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.

Upvotes: 1

Related Questions