Articles → .NET → Get List Of Installed Printers In C#

Get List Of Installed Printers In C#







Picture showing the list of printers installed in the windows operating system
Click to Enlarge



  1. First of all create a console application (you can create any application type) and add the reference of System.Management.dll to the project.
  2. Add following code in main method
using System;
using System.Management;

namespace Check_Connection_With_Printer {
  class Program {
    static void Main(string[] args) {
      ManagementScope scope = new ManagementScope(@ "\\your_computer_ip\root\cimv2");
      scope.Connect();

      ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, new ObjectQuery("SELECT * FROM Win32_Printer"));
      searcher.Options.Timeout = new TimeSpan(0, 0, 2);

      ManagementObjectCollection collection = searcher.Get();

      try {
        foreach(ManagementObject m in collection) {
          Console.WriteLine(m["name"]);
        }
      } catch (ManagementException ex) {
        if (ex.ErrorCode == ManagementStatus.Timedout)
          Console.WriteLine("No printer configured");
      }
      Console.ReadLine();
    }
  }
}





Output


Picture showing the list of printers installed in window operating system using C#
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, May 26, 2015

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250