views:

1227

answers:

7

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.

A: 

This is not the ideal solution, but if nobody else answers, you can create a temp batch file and invoke that through C#/VB.NET.

Someone else will probably know a more natural way to do this.

pyrochild
+3  A: 

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).

Kevin Pullin
+1 for being better than my answer ;)
pyrochild
A: 

Hi Ichiban,

You will need to wrap the setup APIs using PINVOKE or a native COM object.

Foredecker
+2  A: 

You are going to want to look at the WMI objects available. These give you a finer control of the local machine settings. Take a look at the WMI code creator from Microsoft, I believe this will generate some example code you can leverage to solve your problem.

crawdog
+1 : Nice tool...
Dscoduc
Yeah awesome tool
Raymund
A: 

Administering Printer Settings in C# for Flexible Printing

see this article, it uses an MS Platform SDK DLL called PRNADMIN to manage printers, printer-drivers, printer-ports, ...etc.

I personally use it in a commercial project to install a printer driver and change the printer port to local port to intercept the Postscript. and it works like a Charm.

Alternatively you can use some pre-installed vbscripts that come with windows in C:\Windows\system32\Printing_Admin_Scripts and here is a an articles for them:

http://technet.microsoft.com/en-us/library/cc771846.aspx

Code Guru
A: 

I always revert to the following links to install printers 'programatically'.

http://support.microsoft.com/kb/314486

http://www.robvanderwoude.com/2kprintcontrol.php

Douglas Anderson
A: 

if u need a printer,barcode printer,card printer u can find in http://www.autoidmart.com

TarunaIndy