mac_shinobi (25th May 2010)
Hi all
I have a networked printer in one of my schools and i am trying to automate the installation of it through a batch file.
I have to install it through it's IP Address (no print servers unfortunately). This is fine i have got a registry key which creates the port:
(i have left the IP address out)Code:Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\] "Protocol"=dword:00000001 "Version"=dword:00000001 "HostName"="" "IPAddress"="" "HWAddress"="" "PortNumber"=dword:0000238c "SNMP Community"="public" "SNMP Enabled"=dword:00000001 "SNMP Index"=dword:00000001
the registry is silently imported through the batch file, spooler service is the stopped and restarted to refresh the ports. i then use printui.dll to install the printer. I specified the inf file i used in the add printer wizard and this is where it fails.
When i run the batch file it tells me that it is unable to find a suitable driver. this is the only printer i cannot install through this method.
Does anyone have any ideas?
You can use the rundll method to install a standard tcp/ip or LPR port as well as using an inf file to install the driver
How to add printers with no user interaction in Windows
How to add printers with no user interaction in Windows XP
Command Line Printer Control
On this article
RunDLL32
There are related articles which may be of interest at the bottom
Thanks for responding, i'm able to install the port fine it's just that rundll32 and the printui.dll are not recognising any inf file from the drivers even though i am using the same files for the add printer wizard.
can you post back with the rundll command you are using and also you mention the printui.dll ( how does that come into it ? )
Just as an example from the windows xp rundll command
The \if command switch should allow you to specify the relevant inf file, I am guessing they will need copying to the windows/inf directory possibly ??rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f
%windir%\inf\ntprint.inf /r "IP_157.57.50.98" /m "HP Laserjet 4000 Series PCL" /Z

Assuming you are using the 32-bit PCL6 driver on Windows XP, the batch file below should do what you want. You just need to change the IP address and driver paths in the variables section.
Code:@ECHO OFF :: =========================================================== :: Installs HP Color LaserJet CP3525n printer :: Based on batch file from RSCWM: http://goo.gl/JB2J :: =========================================================== :: =========================================================== :: VARIABLES :: =========================================================== Set PRNSCRIPTDIR=%SystemRoot%\System32 Set PRINTER=HP Color LaserJet CP3525 PCL 6 Set SHARENAME=HP Colour LaserJet CP3525n Set IPADDR=192.168.0.254 :: Note double backslashes below Set DRVFOLDER=C:\\HP_CLJ_CP3525_32bit_PCL6\\ Set DRVINF=C:\\HP_CLJ_CP3525_32bit_PCL6\\hpc3525c.inf :: =========================================================== :: Check whether printer exists and is default printer cscript /nologo %PRNSCRIPTDIR%\prnmngr.vbs -g | FINDSTR /c:"%PRINTER%" IF %ERRORLEVEL% EQU 0 GOTO :SHAREPRINTER :: Check whether printer exists, but is not the default printer cscript /nologo %PRNSCRIPTDIR%\prnmngr.vbs -l | FINDSTR /c:"%PRINTER%" IF %ERRORLEVEL% EQU 0 GOTO :SETDEFAULT :: Check whether printer driver is installed cscript /nologo %PRNSCRIPTDIR%\prndrvr.vbs -l | FINDSTR /c:"%PRINTER%" :: If it isn't, install driver IF %ERRORLEVEL% NEQ 0 rundll32 printui.dll,PrintUIEntry /ia /b "%PRINTER%" /f "%DRVINF%" /r IP_%IPADDR% /m "%PRINTER%" IF %ERRORLEVEL% NEQ 0 EXIT /B :: Check whether printer port exists cscript /nologo %PRNSCRIPTDIR%\prnport.vbs -l | FINDSTR /c:"%IPADDR% :: If it isn't, create port IF %ERRORLEVEL% NEQ 0 cscript /nologo %PRNSCRIPTDIR%\prnport.vbs -a -r IP_%IPADDR% -o raw -n 9100 -me -i 1 -y public -h %IPADDR% IF %ERRORLEVEL% NEQ 0 EXIT /B :: Create printer cscript /nologo %PRNSCRIPTDIR%\prnmngr.vbs -a -p "%PRINTER%" -m "%PRINTER%" -r IP_%IPADDR% IF %ERRORLEVEL% NEQ 0 EXIT /B :: Set as default printer :SETDEFAULT cscript /nologo %PRNSCRIPTDIR%\prnmngr.vbs -t -p "%PRINTER%" :: Check if printer is shared. If it isn't, share it. :SHAREPRINTER WMIC PRINTER where "PortName='IP_%IPADDR%'" GET Shared | FINDSTR /c:"FALSE" IF %ERRORLEVEL% EQU 0 cscript /nologo %PRNSCRIPTDIR%\prncnfg.vbs -t -p "%PRINTER%" -h "%SHARENAME%" -m "Comment" -l "Location" +shared -direct
HPs latest printer drivers are a little strange in that you can't use prndrvr.vbs to install them, you have to to use the rundll32 method with the /ia switch. If you use the /if switch you will receive an error stating "The argument is invalid". This also means you can't use /Z to share the printer so you need to use prncnfg.vbs to do that. If you have any non-HP printers you can replace the line containing rundll32 with the following.
Code:IF %ERRORLEVEL% NEQ 0 cscript /nologo %PRNSCRIPTDIR%\prndrvr.vbs -a -m "%PRINTER%" -h "%DRVFOLDER" -i "%DRVINF%"
Last edited by Arthur; 23rd May 2010 at 07:31 PM. Reason: Updated Script
Thanks for the posts.
The batch file i am using contains the following commands
I have used that rundll method with other printers before using a batch file. it's just this one that doesn't work.Code:Echo off cls Echo "*******************************************************" Echo "****************Installing Printer*********************" Echo "*******************************************************" Echo. Echo. Echo "Creating Printer Port" regedit /s "\\server\Installation Packages\Printer Installers\IT suite.reg" Echo. Echo. Echo Spooler Service Restarting net stop spooler net start spooler Echo Spooler Service Restarted Echo. Echo "Printer Port Created" Echo. Echo. Echo "Installing Drivers" rundll32 printui.dll,PrintUIEntry /if /b "HP Colour Laserjet 3525n" /f "\\server\Apps\Printer Drivers\HP Colour Laserjet 3525n\hpc3525c.inf" /r "IP_xxx.xxx.xxx.xxx" /m "HP Colour Laserjet 3525n" Echo. Echo "Drivers Installed" Echo. Echo Printer Installation Complete Echo. Echo. Echo. Pause

This line in your script...
Code:rundll32 printui.dll,PrintUIEntry /if /b "HP Colour Laserjet 3525n" /f "\\Server\Apps\Printer Drivers\HP Colour Laserjet 3525n\hpc3525c.inf" /r "IP_xxx.xxx.xxx.xxx" /m "HP Colour Laserjet 3525n"
needs to be changed to...
Code:rundll32 printui.dll,PrintUIEntry /ia /b "HP Color LaserJet CP3525 PCL 6" /f "\\Server\Apps\Printer Drivers\HP Colour Laserjet 3525n\hpc3525c.inf" /r "IP_xxx.xxx.xxx.xxx" /m "HP Color LaserJet CP3525 PCL 6"
If you want to give it a try, I have combined your batch file with parts of mine and come up with the one below (which will work on XP and Vista/7). As long as you are using the PCL6 driver, this will do it.
Code:@echo off & cls Call :GetOS SET PRINTER=HP Color LaserJet CP3525 PCL 6 SET IPADDR=xxx.xxx.xxx.xxx echo ******************************************************* echo **************** Installing Printer ******************* echo ******************************************************* echo. echo Creating Printer Port echo. cscript /nologo %PRNSCRIPTDIR%\prnport.vbs -a -r IP_%IPADDR% -o raw -n 9100 -me -i 1 -y public -h %IPADDR% echo. echo Printer Port Created echo. echo Installing Drivers echo. rundll32 printui.dll,PrintUIEntry /ia /b "%PRINTER%" /f "\\Server\Apps\Printer Drivers\HP Colour Laserjet 3525n\hpc3525c.inf" /r IP_%IPADDR% /m "%PRINTER%" echo. echo Drivers Installed echo. echo Printer Installation Complete echo. PAUSE goto :EOF :: ******************************************************* :: **************** Check Windows Version **************** :: ******************************************************* :GetOS ver | findstr /i "5\.0\." > nul IF %ERRORLEVEL% EQU 0 goto 2000 ver | findstr /i "5\.1\." > nul IF %ERRORLEVEL% EQU 0 goto XP ver | findstr /i "5\.2\." > nul IF %ERRORLEVEL% EQU 0 goto 2003 ver | findstr /i "6\.0\." > nul IF %ERRORLEVEL% EQU 0 goto Vista ver | findstr /i "6\.1\." > nul IF %ERRORLEVEL% EQU 0 goto 7 goto UnknownOS :7 SET PRNSCRIPTDIR=%SystemRoot%\System32\Printing_Admin_Scripts\en-US goto :EOF :Vista SET PRNSCRIPTDIR=%SystemRoot%\System32\Printing_Admin_Scripts\en-US goto :EOF :2003 SET PRNSCRIPTDIR=%SystemRoot%\System32 goto :EOF :XP SET PRNSCRIPTDIR=%SystemRoot%\System32 goto :EOF :2000 echo Windows 2000 is not supported goto :EOF :UnknownOS echo Operating system cannot be determined. goto :EOF
Last edited by Arthur; 24th May 2010 at 10:52 PM.
Not sure if it makes any difference with bat files but when using vbscript I have had to be specific as to where the rundll32 exe was when launching it ie
c:\windows\system32\rundll32.exe printui.dll,PrintUIEntry etc etc etc

I can't say I have ever had to specify the path to rundll32. It has always worked for me. e.g.
Code:Option Explicit Dim WshShell,Printer,Port,Driver,Return Set WshShell = WScript.CreateObject("WScript.Shell") Printer = "HP Color LaserJet CP3525 PCL 6" Port = "IP_192.168.0.254" Driver = "C:\HP_CLJ_CP3525_32bit_PCL6\hpc3525c.inf" Return = WshShell.Run("rundll32 printui.dll,PrintUIEntry /ia /b """ & Printer & """ /f """ & Driver & """ /r """ & Port & """ /m """ & Printer & chr(34))
mac_shinobi (25th May 2010)
Because the Printer Name has to be the same as the name in the inf file is there anyway to read the inf file using fso or the likes so as long as the hta is in the same directory it can find and read the inf file to determine the printer name
which section of the inf file as well because looking at the pcl 5 driver oemsetup.inf file there are a few mentions of it being a ricoh aficio mpc 3000 pcl 5 etc
Also found this, not sure if its of any use
http://www.computerperformance.co.uk/ezine/ezine118.htm
Last edited by mac_shinobi; 25th May 2010 at 10:57 AM.

There probably is a way to do this, but I'm not quite sure how to do it (maybe srochford knows). Some printer drivers list more than one printer model in their INFs which complicates things even further.
That was or is the issue I am having and am getting confused , as an example downloaded and extracted the pcl 5 driver for windows xp 32 bit for an MPC 3000 and it even refers to MPC 2000 and MPC 2500 as well as the MPC 3000
Would using wmi work ok on windows 7 / vista / xp ??
http://www.activexperts.com/activmon...rinting/ports/
If so I can add the port and driver using wmi
Then it would be a case of using the ms kb to add the printer using the already pre created tcp/ip port with an already installed driver etc
Last edited by mac_shinobi; 25th May 2010 at 06:57 PM.
Arthur
Thanks for your script it works to a point unfortuantely though. It creates the port with no problems it even installs the driver!! but it won't actually create the printer in my Printers and Faxes folder. any ideas why??
Thanks again
EDIT - NVM figured it out - changed the /ia to /if as /ia only installs the drivers not the printer.
Thanks for all your help.
Last edited by LeightonJames; 28th May 2010 at 03:39 PM. Reason: Found solution

Hi Leighton,
Thanks for the update. I forgot to add the line that actually creates the printer (after the rundll32 line).
Code:echo. echo Creating printer echo. cscript /nologo %PRNSCRIPTDIR%\prnmngr.vbs -a -p "%PRINTER%" -m "%PRINTER%" -r IP_%IPADDR%
The script should therefore look like this now (assuming you were using the one in post #7).
Code:@echo off & cls Call :GetOS SET PRINTER=HP Color LaserJet CP3525 PCL 6 SET IPADDR=xxx.xxx.xxx.xxx echo ******************************************************* echo **************** Installing Printer ******************* echo ******************************************************* echo. echo Creating Printer Port echo. cscript /nologo %PRNSCRIPTDIR%\prnport.vbs -a -r IP_%IPADDR% -o raw -n 9100 -me -i 1 -y public -h %IPADDR% echo. echo Printer Port Created echo. echo Installing Drivers echo. rundll32 printui.dll,PrintUIEntry /ia /b "%PRINTER%" /f "\\Server\Apps\Printer Drivers\HP Colour Laserjet 3525n\hpc3525c.inf" /r IP_%IPADDR% /m "%PRINTER%" echo. echo Creating printer echo. cscript /nologo %PRNSCRIPTDIR%\prnmngr.vbs -a -p "%PRINTER%" -m "%PRINTER%" -r IP_%IPADDR% echo. echo Drivers Installed echo. echo Printer Installation Complete echo. PAUSE goto :EOF :: ******************************************************* :: **************** Check Windows Version **************** :: ******************************************************* :GetOS ver | findstr /i "5\.0\." > nul IF %ERRORLEVEL% EQU 0 goto 2000 ver | findstr /i "5\.1\." > nul IF %ERRORLEVEL% EQU 0 goto XP ver | findstr /i "5\.2\." > nul IF %ERRORLEVEL% EQU 0 goto 2003 ver | findstr /i "6\.0\." > nul IF %ERRORLEVEL% EQU 0 goto Vista ver | findstr /i "6\.1\." > nul IF %ERRORLEVEL% EQU 0 goto 7 goto UnknownOS :7 SET PRNSCRIPTDIR=%SystemRoot%\System32\Printing_Admin_Scripts\en-US goto :EOF :Vista SET PRNSCRIPTDIR=%SystemRoot%\System32\Printing_Admin_Scripts\en-US goto :EOF :2003 SET PRNSCRIPTDIR=%SystemRoot%\System32 goto :EOF :XP SET PRNSCRIPTDIR=%SystemRoot%\System32 goto :EOF :2000 echo Windows 2000 is not supported goto :EOF :UnknownOS echo Operating system cannot be determined. goto :EOF
Edit. Glad you go it working.![]()
Last edited by Arthur; 28th May 2010 at 03:44 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)