Articles → .NET → Get list of installed printers in C#

Get list of installed printers in C#








Click to Enlarge







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



Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250