Listing Printers in C#

Introduction

This code example lists all the printers in the network, it is support both window and web based application

ManagementScope objScope = new ManagementScope(ManagementPath.DefaultPath); //For the local Access

objScope.Connect();

SelectQuery selectQuery = new SelectQuery();

selectQuery.QueryString = "Select * from win32_Printer";

ManagementObjectSearcher MOS = new ManagementObjectSearcher(objScope, selectQuery);

ManagementObjectCollection MOC = MOS.Get();

List<string> printers = new List<string>();

foreach (ManagementObject mo in MOC)

{

printers.Add(mo["Name"].ToString().ToUpper());

}