List of UNC Paths to networked printers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drewgy
    New Member
    • Apr 2007
    • 1

    #1

    List of UNC Paths to networked printers

    Can anyone tell me how to get a list of full UNC paths for all printers on a network?

    I have tried using WMI but the following code only gives me a list of local printers, and doesn't give me the fully qualified paths.
    Code:
    private void GetNetworkPrinters()
            {
                try
                {
    
                    string strQuery = "SELECT * FROM Win32_Printer";
    
                    ObjectQuery objectQuery = new ObjectQuery(strQuery);
                    ManagementScope scope = new ManagementScope("\\\\" + EMServer.UserConsole.ApplicationEnvironment.RemoteServerID + "\\root\\cimv2");
                    ManagementObjectSearcher query = new ManagementObjectSearcher(scope, objectQuery);
                    ManagementObjectCollection printers = query.Get();
    
                    foreach (ManagementObject printer in printers)
                    {
                        PropertyDataCollection propertyDataCollection = printer.Properties;
                        this.cboPrinter.Items.Add("\\\\" + printer["Location"] + "\\" + printer["Name"]);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    Thanks

    Drewgy
    Last edited by tlhintoq; Mar 2 '09, 01:23 PM. Reason: [CODE] ...your code here...[/CODE] tags added
Working...