How to list all printers on network computer

15,075

Simply,

via System.Drawing.Printing

foreach (String printer in PrinterSettings.InstalledPrinters)
{
    Console.WriteLine(printer.ToString()+Environment.NewLine);
} 

via WMI

public static void AvailablePrinters()
{
 oManagementScope = new ManagementScope(ManagementPath.DefaultPath);
 oManagementScope.Connect();

 SelectQuery oSelectQuery = new SelectQuery();
 oSelectQuery.QueryString = @"SELECT Name FROM Win32_Printer";

 ManagementObjectSearcher oObjectSearcher = 
    new ManagementObjectSearcher(oManagementScope, @oSelectQuery);
 ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();

 foreach (ManagementObject oItem in oObjectCollection)
 {

 Console.WriteLine("Name : " + oItem["Name"].ToString()+ Environment.NewLine);
 }
}

via PowerShell

Get-WMIObject -class Win32_Printer -computer $printserver | Select Name,DriverName,PortName

For more information, please check this article & WMI Printer Class

Share:
15,075
dance2die
Author by

dance2die

I like to read, and build(& break?) stuff. Currently helping folks out on r/reactjs & DEV#react. Reach out to me @dance2die & check out my blog on sung.codes

Updated on June 04, 2022

Comments

  • dance2die
    dance2die about 2 years

    As shown below in the picture, when I tried to retrieve all printers, I got only 2 printers.

    Is there a way to return all printers using either PowerShell WMI or C#(so that I can translate it in powershell)?

    I have tried System.Drawing.Printing.PrinterSettings.InstalledPrinters (refer to how to get the list of all printers in computer - C# Winform) but also displays only 2 entries.

    enter image description here