Troubleshooting scripted printer driver installations

I came across an interesting problem one day when I was trying to install a printer driver in Windows XP through known-working vbscript files. One script was custom made and the other was the built-in prndrvr.vbs file included with the operating system. The same driver that installed without a problem using the Add a Printer wizard won’t install when using vbscript. All I would get back is a simple error code 2.

After referencing Microsoft’s MSDN article on the Win32_PrinterDriver.AddPrinterDriver method, I was pointed to the standard WMI Error Constants page, which then told me to use the system’s built-in net helpmsg command to find out what the error code 2 was: The system cannot find the file specified.

I found that to be odd – how can a file be missing if that same driver package works 100% when using the GUI to install it? To find out what was going on, I made use of the Microsoft SetupAPI log file. Details are available in a whitepaper at Microsoft’s Windows Hardware Developer Central. While the whitepaper goes into extreme details, I only needed to do the basics to determine the cause of this installation failure. I left the SetupAPI log level at 0, which proved to be sufficient.

For simplicity in documentation, I used the existing prndrvr.vbs file that is included in Windows XP. The results of my findings are shown below:

Command entered:
cscript prndrvr.vbs -a -m “HP LaserJet P4010_P4510 Series PCL 6” -v 3 -e “Windows NT x86” -i “I:\\Public\\Drivers\\HP LaserJet P4010 Series\\hpc4015c.inf”

Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Unable to add printer driver HP LaserJet P4010_P4510 Series PCL 6 Win32 error code 2

Result in C:\Windows\Setupapi.log:
[SetupAPI Log]
OS Version = 5.1.2600 Service Pack 3
Platform ID = 2 (NT)
Service Pack = 3.0
Suite = 0x0100
Product Type = 1
Architecture = x86
[2009/05/11 09:49:47 4216.4 Driver Install]
#-198 Command line processed: C:\WINDOWS\system32\wbem\wmiprvse.exe
#I060 Set selected driver.
#I060 Set selected driver.
[2009/05/11 09:49:47 4216.5]
#-198 Command line processed: C:\WINDOWS\system32\wbem\wmiprvse.exe
#-167 SPFILENOTIFY_NEEDMEDIA: Tag = ““, Description= “HP LaserJet P4015/4014/4515 PCL 6 CD”, SourcePath = “i:\ public\drivers\hp laserjet p4010 series”, SourceFile = “UNIDRV.HLP“, Flags = 0x00000000.
#E169 SPFILENOTIFY_NEEDMEDIA: returned FILEOP_ABORT. Error 2: The system cannot find the file specified.
#W187 Install failed, attempting to restore original files.

As it can be seen from the log file, the WMI method Win32_PrinterDriver.AddPrinterDriver could not locate the file, which contains the English localized copy of unidrv.hlp. To help WMI out I simply extracted the unidrv.hlp file from to the folder containing the driver files. Since all the Windows installations I deal with are English localized (and the fact that I don’t know of anyone who actually uses the printer driver help file), forcing an English localization isn’t a problem.

After adding the “missing” file to the install folder and executing the vbscript again the print driver installed without a problem.

9 Replies to “Troubleshooting scripted printer driver installations”

  1. jim smith

    Thanks for this entry. I couldn’t for the life of me figure out what error code 2 was which I started getting after I fixed the unsigned driver issue.

  2. Mikel


    you are a genius!!

    i have been working for months trying to fix this issue!

    This fix works both with HP 6040 and HP Universal Driver PCL 5,

    which are the 2 models i have been having huuuge issues with error 2.

    thanks again.

  3. Marcus

    This was exactly my problem that I had with the HP Universal Printing PCL 6 driver. I use WMI and .NET to install the drivers. Look at my website for details. Thanks!

  4. Rudolf

    This was exactly my problem that I had with the HP Universal Printing PCL 6 driver. I use WMI and .NET to install the drivers. Look at my website for details. Thanks!

  5. Warren

    Thank you I thought there was no hope using the prndrvr.vbs. A simple help file causing all this frustration.

  6. Sharon Turner

    Error codes could make you go Dick Dastardly and say drat, drat and double drat but with someone like you posting something very helpful like this… may the drat, drat and double drat be reversed.

  7. Jane Forrington

    Great that you have put in so much effort to trouble shoot the problem. I would have simply heeded the advice and used the “add printer” function to get the job done.

Leave a Reply

Your email address will not be published.