How to get all installed printers name on your machine in C#

The .Net Framework provides ‘PrinterSetings’ class which has ‘PrinterSettings.InstalledPrinters’ property, this property can be used to get the names of all printers installed on the computer.

The following code example populates the ComboBox control with the installed printers. The ‘PrinterSetings’ class class is located in System.Drawing.Printing namespace so you need to import ‘System.Drawing’ with using statement in your working class.

private void GetInstalledPrinters()
   {
       // Bind installed printers found to the combo box.
       // The InstalledPrinters string will be used to provide the display string.
       String InstalledPrinter;
       for (int count = 0; count < PrinterSettings.InstalledPrinters.Count; count++)
          {
             InstalledPrinter = PrinterSettings.InstalledPrinters[count];
             ddInstalledPrinters.Items.Add(InstalledPrinter);
          }
    }

The above code requires a ComboBox control named ‘ddInstalledPrinters’ on a window form. We are iterating on ‘PrinterSettings.InstalledPrinters’ and binding each printer name in combo box.

How to know that which printer is default printer?

The following example demonstrates how to use the ‘IsDefaultPrinter’ property. The example populates all available printer names into the combobox control and default printer name will be selected by default.

private void GetInstalledPrinters()
{
    String InstalledPrinter;
	PrinterSettings settings = new PrinterSettings();
    for (int count = 0; count < PrinterSettings.InstalledPrinters.Count; count++)
    {
        InstalledPrinter = PrinterSettings.InstalledPrinters[count];
		ddInstalledPrinters.Items.Add(InstalledPrinter);
 
		settings.PrinterName = InstalledPrinter;
		if (settings.IsDefaultPrinter){
            ddInstalledPrinters.Text = InstalledPrinter;
		}
    }
}

If the available printers cannot be enumerated then exception will be thrown.

List of Installed Printers on the Network Using WMI

Another approach is using Windows Management Instrumentation(WMI), you’ll need to add a reference to the System.Management assembly then import it with ‘using’ statement.

using System.Management;
private void GetInstalledPrinters()
{
    ObjectQuery oquery =
                new ObjectQuery("SELECT * FROM Win32_Printer");
	ManagementObjectSearcher mosearcher =
                new ManagementObjectSearcher(oquery);
 
    ManagementObjectCollection moc = mosearcher.Get();
 
    String InstalledPrinter;
    foreach (ManagementObject mo in moc)
    {
        System.Management.PropertyDataCollection pdc = mo.Properties;
        foreach (System.Management.PropertyData pd in pdc)
        {
            if ((bool)mo["Network"])
            {
                ddInstalledPrinters.Items.Add(mo[pd.Name]);
            }
        }
    }
}

The Windows Management Instrumentation (WMI) infrastructure is very usefult. You can use this to know any management information and events about the system, and devices. Applications and services can query for management information such as about the disk drive or any process. For the example query ‘select * from Win32_Process‘ returns the list of processes running on a computer.