Articles → .NET → Get List Of Installed Printers In C#
Get List Of Installed Printers In C#
Click to Enlarge
- First of all create a console application (you can create any application type) and add the reference of System.Management.dll to the project.
- 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
Click to Enlarge