+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Scripts Thread, Installing HP Colour Laserjet c3525n using inf files in Coding and Web Development; Hi all I have a networked printer in one of my schools and i am trying to automate the installation ...
  1. #1

    LeightonJames's Avatar
    Join Date
    Sep 2009
    Posts
    634
    Thank Post
    26
    Thanked 92 Times in 60 Posts
    Rep Power
    268

    Installing HP Colour Laserjet c3525n using inf files

    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:

    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
    (i have left the IP address out)

    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?

  2. #2

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,052
    Thank Post
    3,583
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    Quote Originally Posted by LeightonJames View Post
    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:

    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
    (i have left the IP address out)

    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

  3. #3

    LeightonJames's Avatar
    Join Date
    Sep 2009
    Posts
    634
    Thank Post
    26
    Thanked 92 Times in 60 Posts
    Rep Power
    268
    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.

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,052
    Thank Post
    3,583
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    Quote Originally Posted by LeightonJames View Post
    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

    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
    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 ??

  5. #5


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    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

  6. #6

    LeightonJames's Avatar
    Join Date
    Sep 2009
    Posts
    634
    Thank Post
    26
    Thanked 92 Times in 60 Posts
    Rep Power
    268
    Thanks for the posts.

    The batch file i am using contains the following commands

    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
    I have used that rundll method with other printers before using a batch file. it's just this one that doesn't work.

  7. #7


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Quote Originally Posted by LeightonJames View Post
    I have used that rundll method with other printers before using a batch file. It's just this one that doesn't work.

    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.

  8. #8

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,052
    Thank Post
    3,583
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    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

  9. #9


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    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))

  10. Thanks to Arthur from:

    mac_shinobi (25th May 2010)

  11. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,052
    Thank Post
    3,583
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    Quote Originally Posted by Arthur View Post
    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))
    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.

  12. #11


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Quote Originally Posted by mac_shinobi View Post
    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
    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.

  13. #12

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,052
    Thank Post
    3,583
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    Quote Originally Posted by Arthur View Post
    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.

  14. #13


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    Quote Originally Posted by mac_shinobi View Post
    Would using wmi work ok on windows 7 / vista / xp ??
    You shouldn't have any problems on those OSs. In fact, it's what prndrvr.vbs and all the other VBScripts use.
    Last edited by Arthur; 25th May 2010 at 08:14 PM. Reason: Just saw your other thread. :-)

  15. #14

    LeightonJames's Avatar
    Join Date
    Sep 2009
    Posts
    634
    Thank Post
    26
    Thanked 92 Times in 60 Posts
    Rep Power
    268
    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

  16. #15


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,793
    Thank Post
    262
    Thanked 2,964 Times in 2,179 Posts
    Rep Power
    846
    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.



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [Wanted] HP Colour Laserjet 2600n Printers
    By eddyc in forum Classified Adverts
    Replies: 2
    Last Post: 27th January 2010, 10:19 AM
  2. HP Colour Laserjet 2025 network printer
    By silver in forum Hardware
    Replies: 7
    Last Post: 3rd March 2009, 12:07 PM
  3. HP Laserjet 3505 colour
    By jack_knows in forum Hardware
    Replies: 0
    Last Post: 17th September 2008, 10:52 AM
  4. HP Colour LaserJet 4550 Toner
    By BaccyNet in forum General Chat
    Replies: 0
    Last Post: 2nd January 2008, 06:52 PM
  5. HP Colour Laserjet 2550l
    By button_ripple in forum Hardware
    Replies: 7
    Last Post: 10th December 2007, 01:48 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •