Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Programmatic Printer Driver Installation re-visited for Vista

On this page:

A long while back I posted an entry regarding how to install a printer driver programmatically by shelling out and using rundll32.exe to execute the PrintUi.dll which can handle a variety of print tasks including installing a printer driver. This code's been working fine, but it's been giving me some problems under Vista for a couple of reasons.

The firsts issue is that I use the driver to install a PostScript driver so I can print a PostScript file to disk which later can be converted by GhostScript. To do this I've been using one of the default installed printer drivers for Windows which has been:

Apple Color LW 12/660 PS

Unfortunately this driver no longer exists in the default printer list in Vista. In fact, Microsoft ditched all the Apple printers - well they are a bit uhm dated. <s> So the next step was to find a driver that exists under WinXp, Win2003 and Vista (don't have older versions around to check but it might work under Win2k as well). The driver I ended up picking was:

Xerox Phaser 1235 PS

But even after switching to the new and available printer I continued to get error message from the driver installation routine. The main reason is that I previously had used the /v[ersion] switch with "Windows 2000 and XP" which works fine for all OS's through XP. On Vista however, only "Windows XP" works explicitly (there's no Windows Vista switch as far as I can tell).

In the end the following two command lines will install the printer driver:

C:\Windows\system32\rundll32.exe printui.dll,PrintUIEntry /ia /m "Xerox Phaser 1235 PS" /h "Intel" /v "Windows XP" /f "C:\Windows\inf\ntprint.inf" /u
C:\Windows\system32\rundll32.exe printui.dll,PrintUIEntry /if /b "Xerox Phaser 1235 PS" /f "C:\Windows\inf\ntprint.inf" /r "lpt1:" /m "Xerox Phaser 1235 PS"

I'm using this code as part of a setup routine that runs inside of West Wind Web Connection (a FoxPro application) application and here's the complete logic to do the driver installation:


* InstallPrinterDriver


***  Function: Installs a Windows Printer driver from the stock

***            Windows driver library

***    Assume:

***      Pass:

***    Return:


FUNCTION InstallPrinterDriver(lcDriverName,lcPrinterName)

LOCAL lcOs, llResult


IF EMPTY(lcDriverName)

 *** This color PS driver exists under Win2003, Vista and XP

 lcDriverName = "Xerox Phaser 1235 PS"

 * lcDriverName = "Apple Color LW 12/660 PS"


IF EMPTY(lcPrinterName)

  lcPrinterName = lcDriverName


LOCAL ARRAY laPrinters[1]


lnCount = APRINTERS(laPrinters)

FOR lnX = 1 TO lnCount

   IF LOWER(lcPrinterName) == LOWER(laPrinters[lnX,1])

      RETURN .t.




lcOS = "Windows 2000 or XP"

IF OS(3) = "6"  && Vista requires XP setting

   lcOS = "Windows XP"




lcExe = loAPI.GetSystemDir() + "rundll32.exe"

lcCmdLine = [printui.dll,PrintUIEntry /ia /m "] + lcDriverName + [" /h "Intel" /v "] + lcOS + [" /f "] + loAPI.GetSystemDir(.t.)+ [inf\ntprint.inf" /u"]


llResult = CreateProcess(lcExe,lcCmdLine,2,.t.)

IF !llResult




lcCmdLine = [printui.dll,PrintUIEntry /if /b "] + lcPrinterName + [" /f "] + loAPI.GetSystemDir(.T.) + [inf\ntprint.inf" /r "lpt1:" /m "] + lcDriverName + ["]


llResult = CreateProcess(lcExe,lcCmdLine,2,.t.)

IF !llResult






This code should adapt reasonably well to anything that can shell out…


The documentation for printui.dll can be found here:



It's not exactly exhaustive - there's no explanation of any of the switches or which combinations are valid - but if you need to set additional flags it's good place to start experimenting.

Posted in FoxPro  Windows  

The Voices of Reason


# playstation dvd clone pogram

Gosh provides an alternate way to run command- line Groovy scripts, as well as a simplified way to write Windows Services ( WinNT Services ) using Groovy. Gosh treats scripts the same, whether they are run from the command- line or as a service (including bindings). You can debug a service by running it from the command- line, and you can also run standard command- line Groovy scripts. There is very little difference between a Groovy script that is intended to be run as a Windows Service and any other Groovy script.

decrypt a dvd
July 14, 2008

# decrypt a dvd

If you think you might like computer designing worlds and scenes in a video game you should consider being a 2- dimensional artist. They create all the structures, textures and backgrounds in game worlds. Photoshop is the de- facto program for this job. If you can afford a copy of this program you will get a definite insight into this career path. If you cannot afford Photoshop you should consider getting Paint Shop Pro. It is less expensive and very similar to Photoshop and it will give you a good...

free dvd copy
July 15, 2008

# free dvd copy

I have the same problem as Lauretn. I have a USB data cable but I don\'t have its driver, I checked the instructions and I found that it need a driver (SER9PL. INF) and it can be found in the http:// tech. prolific. com. tw/ So I cheched the link but it does not work proparly and face some error in accesing inside this link, and can not find the file. Please direct me to the right link where I can find this file.

July 15, 2008

# www.dvddecoderspro.com

After the initial ogling phase came the dissatisfaction. Not with the box and its software per se , but simply with the fact that its potential wasn’ t maximised. So it was a format and fresh install of Vista- removing all the Dell bloatware in the process and tweaking all the little bits Vista has to offer. After that it was off to http:// www. laptopvideo2go. com for the best performing modded notebook Nvidia drivers for the graphics card, I got myself some Rivatuner goodness to overclock that bugger to...

burn with dvd decrypter
July 15, 2008

# burn with dvd decrypter

Trackback is a technology used by content publishing software like wordpress, movabletype, blogger etc to acknowledge url added in the commenting of post. The trackback acknowledge is sent using network ping from the originating site to receiving site. Let me demostrate how it works with a diagram shown below.

dvd record vhs
July 15, 2008

# dvd record vhs

And last but not least. A camera. My little pocket rocket is about to give up the ghost. I’ ve noticed that the focus is off in the bottom left corner and sometimes it just won’ t focus at all. I’ ve tried cleaning the lense but I think it’ s something internal. Geez, it only cost me 150 so I guess it’ s done it’ s job. So for the next camera, I’ m thinking a Canon EOS 450 or equivalent. I’ ll need to look into it a little more. There is mention of hubby possibly heading over to Hong Kong later in the year,...

best dvd burning
July 15, 2008

# best dvd burning

5 New Versions of the doubleTwist Software. doubleTwist, in its sole discretion, reserves the right to add additional features or functions, or to provide programming fixes, updates and upgrades, to the doubleTwist Software. You acknowledge and agree that doubleTwist has no obligation to make available to You any subsequent versions of the doubleTwist Software, nor any obligation to continue to support prior versions. You also agree that you may have to enter into a renewed version of this Agreement, in...

shrink a dvd
July 16, 2008

# shrink a dvd

Download SugarSync onto your computer (on as many computers as you’ d like, though you only need one), set which folders you’ d like to have synced, and you’ re set. It’ s so easy to use and such a great resource. No more emailing files to myself on gmail, no more flash drives or burning files to disks, no more waiting for files to upload or browsing to find the files with online storage sites…

# www.FreeRegistryCleanerScan.com

And… How do adults handle kids that‘ tune out’ and‘ get embarrassed’ when parents or care- providers attempt to communicate?

August 04, 2008

# www.dvdtocdpro.com

I held the power button for a few seconds to power up and entered into the exact same rebooting situation I had the other day.

rip program
August 04, 2008

# rip program

Recent Posts Google Announces Official DoubleClick Acquisition Affiliate Marketing As A Home Based Business How To Create Free Online Videos With One True Media Free Ebay Report- Simple Ebay Profits How To Set Up Your Amazon Affiliate Video Widget Guest Article: Web 1. 0 vs Web 2. 0 Ebay Book Business Review March 2008 M T W T F S S« Feb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Categories Advertising & Marketing Affiliate Networks Affiliate Programs Announcements...

radio publicity
October 23, 2008

# radio publicity

I found your site on faves.com bookmarking site.. I like it ..gave it a fave for you..ill be checking back later

The Best Laptop Reviews
December 19, 2008

# The Best Laptop Reviews

I personally believe that no best laptop can be universally recognized by all users as long as there are so many manufacturers that produce computers...

June 16, 2010

# re: Programmatic Printer Driver Installation re-visited for Vista

Thank you for this very usefull hint.
It helps me fast and a lot ... ;-)

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024