Click to See Complete Forum and Search --> : [RESOLVED] Printers via C#


JonnyPoet
May 13th, 2008, 11:06 AM
Hi !

How can I find out which printers are available using C#. I need to know which printers are installed on my machine. Thats needed to fill a list with all the printers available so I can select one of them for some specific print job. Or do I need to use API calls. Thx for any help.

HanneSThEGreaT
May 13th, 2008, 11:34 AM
3 Ways I know of :

1) EnumPrinters API (http://www.pinvoke.net/default.aspx/winspool/EnumPrinters.html)

2) PrinterSettings.InstalledPrinters (http://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings.installedprinters(VS.80).aspx)

3) WMI using ManagementObjectSearcher which can be something like :
{
// This connects to the WMI interface
ManagementScope scope = new ManagementScope("root\\default");
scope.Connect();

// This is the actual SQL Statement to get the printers. There is a whole set of classes and such on the WMI interface
ManagementObjectSearcher search = new ManagementObjectSearcher("Select * from win32_printer");

ManagementObject printer;
foreach ( printer in search.Get()) {

// Do what you need to here

}
}

I hope my post was helpful :)

JonnyPoet
May 13th, 2008, 01:12 PM
...I hope my post was helpful :)You saved my day :thumb: :thumb: :thumb: :wave: Thx a lot Hannes.