Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install a printer using .NET?

I have an .INF for a virtual printer that I need to install from a .NET Application. I have done this before using batch scripts, but I am looking for a snippet of code to do this in the .NET Framework.

There's nothing particular about the printer .INF, so any code that installs a printer from an INF in C# or VB.NET will work.

like image 208
ichiban Avatar asked May 04 '09 02:05

ichiban


1 Answers

I believe this is possible via interop to native win32 APIs, but I've found its much, much easier just to use a System.Diagnostics.Process() to call into printui.dll via:

rundll32.exe printui.dll,PrintUIEntry /?

Perhaps you're already using that in the mentioned batch script, but if not the parameters are documented here: PrintUI.DLL User's Guide and Reference

Just be sure to test it against all operation systems you need to support. Some options either do not exist in all Windows releases or have been renamed (although I think they're the more esoteric options - installing an .INF will likely work across the board).

like image 51
Kevin Pullin Avatar answered Sep 21 '22 23:09

Kevin Pullin