Installing a Printer Driver programmatically - sort of - using PrintUi.dll
In order to do this though it's a requirement that you actually have a PostScript printer installed on your machine and this becomes an installation hassle. So, it would be nice to automate this process and install a printer driver programmatically. While programmatically is stretching this solution a bit, it turns out that Windows has a utility that allows automating many of the printer installation tasks through the PrintUi.dll utility.
You can run:
rundll32 printui.dll,PrintUIEntry /?
To get the full functionality listing which includes adding and deleting printers both through the Wizards or through non-interactive installs. You can install printers locally or over the network, display status, print test pages, bring up property pages and more.
I ran into a Web board post here that describes some of the options and provides a few examples that make for a great quick start:
http://www.codeguru.com/forum/showthread.php?t=220033&goto=nextoldest
There's also a TechNet entry here:
http://support.microsoft.com/kb/q189105/
For my purpose I want to install a generic PostScript driver for which I've used the Apple Color LW 12/660 PS because it's one that's available on most Windows versions as one of the built in drivers. I was actually thrown by the examples provided in the first article because it takes two steps to register a printer: Load the Printer driver and then install the driver to the local Printers installation.
To register a new printer with the name of Apple Postscript Driver you can use the following (in a batch file or individually):
rundll32 printui.dll,PrintUIEntry /ia /m "Apple Color LW 12/660 PS" /h "Intel" /v "Windows 2000 or XP" /f %windir%\inf\ntprint.inf /u rundll32 printui.dll,PrintUIEntry /if /b "Apple Postscript Driver" /f "%windir%\inf\ntprint.inf" /r "lpt1:" /m "Apple Color LW 12/660 PS"
Works great and provides minimal fuss. To do this programmatically all you need to do is run a Shell process to execute the above commands or execute a batch file. I created a simple batch file called installprinter.bat that does basically this:
rundll32 printui.dll,PrintUIEntry /ia /m "%1" /h "Intel" /v "Windows 2000 or XP" /f %windir%\inf\ntprint.inf /u
rundll32 printui.dll,PrintUIEntry /if /b "%2" /f "%windir%\inf\ntprint.inf" /r "lpt1:" /m "%1"
Note you need to change the server type for Windows NT or Windows 98 systems with the /v flag. The CodeGuru link has a few examples of this and the /? flag describes the various options available when you run it.
Very cool! I'm just bummed it took me so long to find this.
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
- Getting the Client IP Address in ASP.NET Core
The Voices of Reason
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
The printer I want to install uses the local port "NUL". It prints to files, not to a printer... Do you know of a way with the printui.dll to create the NUL port if it doesn't already exist?
Please email me at: srochenh@bigfoot.com if you have any recommendations for me.
Thanks,
Steve
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
Its really cool solution for installing the printer,let me check your specified commands and then i'll let you know what happend next:) BTW is it valid for all NT pro systems e.g. w2K , XP , server 2003.
Great solution with great trick!
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
XP machines. My Syntax is...just like MS Article Q314486
rundll32 printui.dll,PrintUIEntry /if /b "DART" /f %windir%\inf\ntprint.inf
/r "IP_10.0.1.254" /m "HP Laserjet 4000 Series PCL" /Z
I have this statement in a BAT file...when I run it...I get the following
error.
"The arguments are invalid"
Any ideas?
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
I want to add a fresh printer driver(hp bussiness inkjet
1000 series) not existing .
successfully adding the existing printer driver like hp Lseserjet 2100 By using the printui command .but it is not working in the latest printer
eg:
rundll32 printui.dll,PrintUIEntry /ia /c\\Elnet /m "HP Business Inkjet 1000 Series" /h
"Intel" /v "Windows 2000 or XP" /f %windir%\inf\ntprint.inf /l "C:\hp1000k.inf"
reg
Ramesh.k
k_ramesh_7@sify.com
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
rundll32 prinui.dll,PrintUIEntry doesn't work on win98????
please help!!!
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
rundll32 printui.dll,PrintUIEntry /in /ga /c\\remotePC /n"\\Server\printer"
BUT
How can you force it to be the default? When I run
rundll32 printui.dll,PrintUIEntry /y /n \\server\printer
from the local pc it will set the default as expected but I am attemping to do it remote. Any ideas?
Thanks!
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
This works fine on my local PC but I need to add a virtual printer to my webhosts server. Can I do this in ASP.NET so that it executes the batch file server side?
Regards
Mark Lea
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
To do so you can maybe use Impersonation with teh ASPX in a special folder that is Windows Security protected.
http://west-wind.com/weblog/posts/2153.aspx
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
rundll32 printui.dll,PrintUIEntry /if /b "HP LaserJet 4M(IT)" /f %windir%\inf\ntprint.inf /r "IP_143.82.141.243" /m "HP LaserJet 4M Plus" /z
I'm using the above commands to automatically install printer driver onto user machine. My question is which file can I edit or configure the "paper size" or printer properties?? Which file can I use or append a command line to set paper size to A4 instead?
eMail me @ karen_tiong@hotmail.com. Thanks for your help.
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
My questions
1) There are going to be network printers, currently don't have names or ip's, does this matter?
2) If printUI. cannot be used is there a way to at least create something to get the proper inf's and print drivers over to folder so at least all the have do is point to the folder
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
In my case the driver for LaserJet 2420 PCL 6 is not installed. I have the drivers in a share. Can i still use this?
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
During which process do you actually download the printdriver to the computer?
The commands appear to reference the printer name.
Thanks.
Paul
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
The first statement uses the switch "/ia" to install the printer driver, then follow with another (similar) statement using the "/if? switch to actually add the logical printer itself.
By the way, I'm trying to install a no non-WHQL print driver and trying to suppress the prompt that warns me, etc. I've tried using the "/Gw" switch to no avail. Anyone else tried this?
Cheers!
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
Please respond to paulgarth@att.net.
OK.... I'm going through some mentalness here.
Scenario:
-Want to use the two RUNDLL32 lines to install a new printer
-Brand new printer and need to download print driver
Question:
-Where do you put the print driver?
-How does /f "%windir%\inf\ntprint.inf" relate to the print driver name?
The objective is to create Kaseya scripts to install a new printer where they also download the new print driver from the server.
Thanks.
Paul
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
I run this code on myServerName machine without error but no printer(printerName) gets added to the remotePCname.
Any thoughts please?
rundll32 printui.dll,PrintUIEntry /in /ga /c\\reportPCname /n\"\\myServerName\printerName"
# re: Installing a Printer Driver programmatically - sort of - using PrintUi.dll
There are some basic examples of this here:
http://www.jsiinc.com/SUBK/tip5300/rh5379.htm