Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
4.20/5 (3 votes)
See more:
How can I get the list of available printers, not the previous installed or the old installed printers in your computer/laptop but only the available printer/s will appear during the will running?

I've used this code:
C#
foreach (String printer in PrinterSettings.InstalledPrinters)
            {
                //        comboBox1.Items.Add(printer.ToString());
            }

But this is not I want .
Posted
Updated 31-Jan-21 18:17pm
v2
Comments
Sampath Lokuge 4-Feb-14 9:27am    
Check this.http://stackoverflow.com/questions/9791970/how-can-i-list-all-available-printer-drivers-like-the-add-printer-wizard-in-c
Member 10332274 4-Feb-14 9:44am    
But I want only to view the available printer that is/are attached in my computer. Not all the printers that are installed in my computer
User-8621695 4-Feb-14 17:36pm    
For which type of printers list you want windows or POS.

It is possible to get a list of the printers which are ready by using WMI:
(Source[^])

C#
static void PrintProps(ManagementObject o, string prop)
    {
        try { Console.WriteLine(prop + "|" + o[prop]); }
        catch (Exception e) { Console.Write(e.ToString()); }
    }

    static void Main(string[] args)
    {

        ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");

        foreach (ManagementObject printer in searcher.Get())
        {
            string printerName = printer["Name"].ToString().ToLower();
            Console.WriteLine("Printer :" + printerName);

            PrintProps(printer, "Caption");
            PrintProps(printer, "ExtendedPrinterStatus");
            PrintProps(printer, "Availability");
            PrintProps(printer, "Default");
            PrintProps(printer, "DetectedErrorState");
            PrintProps(printer, "ExtendedDetectedErrorState");
            PrintProps(printer, "ExtendedPrinterStatus");
            PrintProps(printer, "LastErrorCode");
            PrintProps(printer, "PrinterState");
            PrintProps(printer, "PrinterStatus");
            PrintProps(printer, "Status");
            PrintProps(printer, "WorkOffline");
            PrintProps(printer, "Local");
        }


As you can see, the "Availability" property will tell you whether the printer is available or not.
 
Share this answer
 
Comments
Member 10332274 4-Feb-14 9:47am    
I've been using a windows form . It is okay to apply that codes?, because as I see the codes it is a console and not windows form. Right ?
LuWa89 21-Nov-16 5:15am    
you can use it in any application
Try this link it may be help you.

http://stackoverflow.com/questions/2354435/how-to-get-the-list-of-all-printers-in-computer-c-sharp-winform[^]

or try according mention below.
C#
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
        {
            comboBox.Item.Add(printer);
        }


hit to reply for any query.
 
Share this answer
 
Comments
Member 10332274 4-Feb-14 10:15am    
But I want is to only appear the available printers not all the printers installed.
joginder-banger 4-Feb-14 10:42am    
i think this is only appear printer is show not all printer.
joginder-banger 4-Feb-14 10:43am    
on my system only two printer are showing, not all Printer install.
Member 10332274 4-Feb-14 10:50am    
It is the two printer are attached to your computer ?
Member 10332274 5-Feb-14 7:53am    
Yes. Two printers are attached . How could be displayed ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900