How to List only Default or Active Printers in .NET?

← Prev

If you want to filter for default or active printers in .NET, especially using WMI, you can do so by querying specific properties of the Win32_Printer class. Here's how you can do this.

list default printers in .net

Filter Default and Active Printers with WMI (C#)

using System;
using System.Management;

class Program
{
    static void Main()
    {
        var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");

        foreach (ManagementObject printer in searcher.Get())
        {
            bool isDefault = Convert.ToBoolean(printer["Default"]);
            string status = printer["Status"]?.ToString() ?? "Unknown";

            if (isDefault || status.Equals("OK", StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine($"Name: {printer["Name"]}");
                Console.WriteLine($"Default: {isDefault}");
                Console.WriteLine($"Status: {status}");
                Console.WriteLine(new string('-', 30));
            }
        }
    }
}

There are two properties that you need to understand.

1) Default: This property indicates if the printer is set as the "system default".

2) Status: The common values of the property includes "OK", "Busy", "Idle" and "Error".

You can modify the condition to suit your needs. For example, only show default and status = OK, or even include additional checks like WorkOffline = false.

← Previous