Get the printers on Printserver

C# Sep 19, 2020 Viewed 291 Comments 0

This article describes how to find printers on the network or server/local.

1. Using EnumeratedPrintQueueTypes

using System;
using System.Linq;
using System.Printing;

namespace PrinterApp
{
    class Printer
    {
        public void FindAllPrinter() {
            var server = new PrintServer();
            PrintQueueCollection queues = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
            var arr = queues.Select(q => q.QueuePort.Name + "  " + q.FullName).ToArray();
            Console.WriteLine(String.Join("\n", arr));
        }
    }
}

Output:

USB001 => Gprinter GP-1324D
USB001 => \\USER-20170818xb\Canon MF4400 Series UFRII LT

Refer to the source code of EnumeratedPrintQueueTypes. You can specify multiple types.

namespace System.Printing
{
    //
    // Summary:
    //     Specifies attributes of print queues.
    [Flags]
    public enum EnumeratedPrintQueueTypes
    {
        //
        // Summary:
        //     A print queue that allows multiple print jobs in the queue.
        Queued = 1,
        //
        // Summary:
        //     A print queue that sends a print job directly to printing instead of spooling
        //     the job first.
        DirectPrinting = 2,
        //
        // Summary:
        //     A print queue that is shared.
        Shared = 8,
        //
        // Summary:
        //     A print queue that is connected to the specified print server.
        Connections = 16,
        //
        // Summary:
        //     A print queue that is installed as a local print queue on the specified print
        //     server.
        Local = 64,
        //
        // Summary:
        //     A print queue that holds its print jobs when the document and printer configurations
        //     do not match.
        EnableDevQuery = 128,
        //
        // Summary:
        //     A print queue that keeps jobs in the queue after printing them.
        KeepPrintedJobs = 256,
        //
        // Summary:
        //     A print queue that can work offline.
        WorkOffline = 1024,
        //
        // Summary:
        //     A print queue for a printer that has bidirectional communication enabled.
        EnableBidi = 2048,
        //
        // Summary:
        //     A print queue that spools only raw data.
        RawOnly = 4096,
        //
        // Summary:
        //     A print queue that is visible in the directory of printers.
        PublishedInDirectoryServices = 8192,
        //
        // Summary:
        //     A print queue that services a fax machine.
        Fax = 16384,
        //
        // Summary:
        //     A print queue that is installed by the redirection feature in Terminal Services.
        TerminalServer = 32768,
        //
        // Summary:
        //     A print queue that was installed by using the Push Printer Connections user policy.
        //     See Remarks.
        PushedUserConnection = 131072,
        //
        // Summary:
        //     A print queue that was installed by using the Push Printer Connections computer
        //     policy. See Remarks.
        PushedMachineConnection = 262144
    }
}

2. With InstalledPrinters

Use PrinterSettings.InstalledPrinters to get the names of all printers installed on the computer.

foreach (string printer in PrinterSettings.InstalledPrinters) {
    Console.WriteLine(printer);
}
Updated Sep 19, 2020