Announcement

Collapse
No announcement yet.

Script for installing local printers with TCP/IP port

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script for installing local printers with TCP/IP port

    Good day,

    I am having some trouble to get the following script to work.

    With the credits to Rob van der Woude:

    Code:
    @ECHO OFF
    :: Check Windows version
    IF NOT "%OS%"=="Windows_NT" GOTO Syntax
    SETLOCAL
    
    :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
    ::                                                                         ::
    ::    Modify the following lines; no quotes for PrnShort and PortIP!       ::
    ::                                                                         ::
    ::    The values for PrnType and TargetOS can be found in the INF file     ::
    ::    that comes with the (extracted) printer driver.                      ::
    ::                                                                         ::
    :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
    
    SET PrnName="Accounting 2nd Floor"
    SET PrnShort=Accounting2
    SET PrnType="Kyocera Mita FS-3820N"
    SET DrvPath="\\server\share\Drivers\Kyocera\FS-3820N\W2K"
    SET InfPath="\\server\share\Drivers\Kyocera\FS-3820N\W2K\oemsetup.inf"
    SET PortIP=112.113.114.115
    SET TargetOS="Windows 2000"
    
    :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
    ::                                                                         ::
    ::       End of adjustments                                                ::
    ::                                                                         ::
    :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
    
    :: Check command line arguments
    IF "%~1"=="" GOTO Syntax
    SET PC=%~1
    ECHO."%PC%" | FINDSTR.EXE /R /C:"[?/]" >NUL && GOTO Syntax
    PING.EXE %PC% 2>NUL | FIND.EXE  "TTL=" >NUL || (
    	ECHO Computer %PC% is unavailable
    	ECHO.
    	GOTO Syntax
    )
    
    :: Check if the required VBScripts are available in the current directory
    SET Error=0
    FOR %%A IN (prncfg prnmgr drvmgr portmgr) DO IF NOT EXIST %%A.vbs SET Error=1
    IF "%Error%"=="1" GOTO Syntax
    
    :: Check if the printer was installed already
    CSCRIPT.EXE //NoLogo prnmgr.vbs -l -c \\%PC% | FIND.EXE /I "%PrnShort%" >NUL && (
    	ECHO A printer named %PrnShort% already exists on %PC%
    	ECHO.
    	GOTO Syntax
    )
    
    :: Check if the printer port was installed already
    CSCRIPT.EXE //NoLogo portmgr.vbs -l -c \\%PC% | FINDSTR.EXE /E /I "IP_%PortIP%" >NUL && (
    	ECHO TCP/IP printer port %PortIP% already exists on %PC%
    	ECHO.
    	GOTO Syntax
    )
    
    :: Prompt the user, and allow him/her to abort the installation
    ECHO You are about to add a local printer %PrnShort% on computer %PC%
    ECHO.
    PAUSE
    
    :: Install the driver
    CSCRIPT.EXE //NoLogo drvmgr.vbs  -a -c \\%PC% -p %DrvPath% -i %InfPath% -v %TargetOS% -m %PrnType% -t Intel
    :: Install the local IP print port, type raw, SNMP disabled
    CSCRIPT.EXE //NoLogo portmgr.vbs -a -c \\%PC% -p IP_%PortIP% -h %PortIP% -t raw -n 9100 -md
    :: Install the local printer with the driver and port we just installed
    CSCRIPT.EXE //NoLogo prnmgr.vbs  -a -c \\%PC% -b %PrnName% -m %PrnType% -r IP_%PortIP%
    :: Configure the local printer as not shared and not published in Active Directory
    CSCRIPT.EXE //NoLogo prncfg.vbs  -s -b \\%PC%\%PrnShort% -published -shared
    
    :: Display or log the configuration of the new printer
    IF /I "%~2"=="/L" (SET Log="%PrnShort%_%PC%.log") ELSE (SET Log=CON)
    (
    	CSCRIPT.EXE //NoLogo drvmgr.vbs  -l -c \\%PC%
    	CSCRIPT.EXE //NoLogo portmgr.vbs -l -c \\%PC%
    	CSCRIPT.EXE //NoLogo prnmgr.vbs  -l -c \\%PC%
    	CSCRIPT.EXE //NoLogo prncfg.vbs  -g -b \\%PC%\%PrnShort%
    ) > %Log% 2>&1
    
    :: Done
    GOTO End
    
    :Syntax
    ECHO.
    ECHO AddIPPrn.bat,  Version 1.01 for Windows 2000 with Server Resource Kit
    ECHO Install a (hard coded) local IP printer %PrnShort% on a remote computer
    ECHO.
    ECHO Usage:  ADDIPPRN.BAT   computername  [ /L ]
    ECHO.
    ECHO Where:  "computername" is the computer on which the printer should be installed
    ECHO         "/L"           logs the results in {printername}_{computername}.log
    ECHO                        (default is display on screen)
    ECHO.
    ECHO Notes:  [1] You need to modify the first couple of lines from this batch file
    ECHO             to install your own printer, port and driver. You may then want
    ECHO             to save the modified batch file as {printername}.bat.
    ECHO         [2] This batch file requires drvmgr.vbs, portmgr.vbs, prnmgr.vbs and
    ECHO             prncfg.vbs from the Windows 2000/2003 Server Resource Kit; these
    ECHO             scripts must all be located in the current directory.
    ECHO         [3] These VBScripts require PRNADMIN.DLL from the Resource Kit to be
    ECHO             installed on the computer that runs the scripts.
    ECHO.
    ECHO Written by Rob van der Woude
    ECHO http://www.robvanderwoude.com
    
    :End
    IF "%OS%"=="Windows_NT" ENDLOCAL
    I am testing this in my private situation with a Deskjet 6620, but i can't get it to work. Adding of the TCP/IP ports does work, but after that he is saying he can't find my printer driver.

    Like Rob van der Woude is explaining in his script i can find the names out the .INF file, but i can't!

    See my 2nd post for the .INF driver of the Printer.

    I have find a script of Microsoft wich is based on VBS, but that script doesn't include a path to a driver

    Could someone help me with this script or if you have a working script wich adds a local printer that would also be good.

  • #2
    Re: Script for installing local printers with TCP/IP port

    The .INF driver contains:


    Code:
    ;HP Printer Driver
    ;Windows 2K-XP non PnP printer installation INF file
    ;Copyright Hewlett-Packard 2004
    
    [Version]
    Signature="$Windows NT$"
    Class=Printer
    ClassGUID={4D36E979-E325-11CE-BFC1-08002BE10318}
    Provider=Hewlett-Packard
    CatalogFile=hpf6600k.cat
    DriverVer=08/17/2004,12.3.1.0
    
    [Manufacturer]
    "Hewlett-Packard"=Models
    
    
    [Models]
    "HP Deskjet 6600 Series"=hp_Install,LPTENUM\HEWLETT-PACKARDDESKJ66000000
    
    ;--------------------------------------------------------------------------------
    ; Install Sections
    ;--------------------------------------------------------------------------------
    
    ;
    ; HP Deskjet 6600 Series
    ;
    [hp_Install]
    CopyFiles=hp_FILES,INST_FILES,HP_COLOR_PROFILES,DD_FILES
    DataSection=COMMON_DRIVER_DATA
    DataFile=hpf53c12.dat
    Include=NTPRINT.INF
    Needs=sRGBPROFILE.OEM
    AddReg=hp_AccessoryReg
    
    
    ;--------------------------------------------------------------------------------
    ; Config/Registry Sections
    ;--------------------------------------------------------------------------------
    
    [COMMON_DRIVER_DATA]
    DriverFile=hpz2ku12.dll
    ConfigFile=hpzpm312.dll
    LanguageMonitor="hpzlnt12,hpzlnt12.dll"
    VendorSetup="hpzcon12.dll,VendorSetup"
    HelpFile=hpfmom12.hlp
    
    
    [hp_AccessoryReg]
    HKLM,"SOFTWARE\Hewlett-Packard\HPZ\Glue\HP Deskjet 6600 Series",InfID,0,"deskjet6600_infid_2k_200007120052"
    HKLM,"SOFTWARE\Hewlett-Packard\HPZ\Glue\HP Deskjet 6600 Series",Product,0,"6600"
    HKLM,"SOFTWARE\Hewlett-Packard\HPDJ Printing System Config\HP Deskjet 6600 Series",DriverVersion,0,"12.3.1.0"
    HKLM,"SOFTWARE\Hewlett-Packard\HPDJ Printing System Config\HP Deskjet 6600 Series",ToolboxExe,0,"hpztbx12.exe"
    HKLM,"SOFTWARE\Hewlett-Packard\HPDJ Printing System Config\HP Deskjet 6600 Series",DriverName,0,"HP Deskjet 6600 Series"
    HKLM,"SOFTWARE\Hewlett-Packard\HPZ\Glue\HP Deskjet 6600 Series",CIOSupport,0,"true"
    HKLM,"SOFTWARE\Hewlett-Packard\San Diego Shared IO",DirectConnectBidiSupported,0x00010001,01,00,00,00
    HKLM,"SOFTWARE\Hewlett-Packard\HPZ\Glue\HP Deskjet 6600 Series",DustDevilSupport,0,"true"
    
    ;--------------------------------------------------------------------------------
    ; CopyFiles Sections
    ;--------------------------------------------------------------------------------
    
    [INST_FILES]
    hpzcon12.dll,,,0x00000020
    hpzcoi12.dll,,,0x00000020
    
    [COINST_FILES]
    hpzcoi12.dll,,,0x00000020
    
    [HP_COLOR_PROFILES]
    "HP Deskjet 6600-Premium High-Gloss Film(tricolor+gray).icc", hpdj66phgftg.icc,,0x00000020
    "HP Deskjet 6600-Premium High-Gloss Film(tricolor+photo).icc", hpdj66phgftp.icc,,0x00000020
    "HP Deskjet 6600-Premium High-Gloss Film(tricolor+black).icc", hpdj66phgftb.icc,,0x00000020
    "HP Deskjet 6600-Premium Paper(tricolor+gray).icc", hpdj66pptg.icc,,0x00000020
    "HP Deskjet 6600-Premium Paper(tricolor+photo).icc", hpdj66pptp.icc,,0x00000020
    "HP Deskjet 6600-Premium Paper(tricolor+black).icc", hpdj66pptb.icc,,0x00000020
    "HP Deskjet 6600-Premium Plus Photo(tricolor+photo).icc", hpdj66ppptp.icc,,0x00000020
    "HP Deskjet 6600-Premium Plus Photo(tricolor+black).icc", hpdj66ppptb.icc,,0x00000020
    "HP Deskjet 6600-Premium Plus Photo(tricolor+gray).icc", hpdj66ppptg.icc,,0x00000020
    
    [DD_FILES]
    hppapml0.dll
    hpbmiapi.dll
    hpboidPS.dll
    hpbproPS.dll
    hpjcmn2u.dll
    hpjipx1u.dll
    hpboid.exe
    hpbpro.exe
    
    [DestinationDirs]
    DefaultDestDir=66000
    INST_FILES=11
    COINST_FILES=11
    DD_FILES=11
    HP_COLOR_PROFILES=66003
    
    [hp_FILES]
    hpf53c12.dat
    hpfmom12.hlp
    hpzcfg12.exe
    hpz2ku12.dll
    hpzcoi12.dll
    hpzcon12.dll
    hpzdiu12.dll
    hpzeng12.exe
    hpzflt12.dll
    hpzime12.dll
    hpzims12.dll
    hpzjui12.dll
    hpzlnt12.dll
    hpzpcl12.dll
    hpzpm312.dll
    hpzpre12.exe
    hpzr3212.dll
    hpzres12.dll
    hpzrm312.dll
    hpzstc12.exe
    hpzstw12.exe
    hpztbi12.dll
    hpztbu12.exe
    hpztbx12.exe
    hpzvip12.dll
    
    [SourceDisksNames]
    1="hp cd",,
    
    [SourceDisksFiles]
    hpf6600p.inf=1,\.
    hpdj66phgftb.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66phgftp.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66phgftg.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66pptb.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66pptp.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66pptg.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66ppptb.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66ppptp.icc=1,..\..\..\common\drivers\win2k_xp
    hpdj66ppptg.icc=1,..\..\..\common\drivers\win2k_xp
    hpf53c12.dat=1,..\com_lang
    hpfmom12.hlp=1,..\com_lang
    hpz2ku12.dll=1,..\..\..\common\drivers\win2k_xp
    hpz9xd12.drv=1,..\..\..\common\drivers\win9x_me
    hpz9xp12.dll=1,..\..\..\common\drivers\win9x_me
    hpzcfg12.exe=1,..\..\..\common\drivers\com_os
    hpzcoi12.dll=1,..\..\..\common\drivers\win2k_xp
    hpzcon12.dll=1,..\..\..\common\drivers\com_os
    hpzdiu12.dll=1,..\..\..\common\drivers\com_os
    hpzeng12.exe=1,..\..\..\common\drivers\com_os
    hpzfac12.dll=1,..\..\..\common\drivers\win9x_me
    hpzflt12.dll=1,..\..\..\common\drivers\com_os
    hpzimb12.dll=1,..\..\..\common\drivers\com_os
    hpzimc12.dll=1,..\..\..\common\drivers\com_os
    hpzime12.dll=1,..\..\..\common\drivers\com_os
    hpzimp12.dll=1,..\..\..\common\drivers\com_os
    hpzims12.dll=1,..\..\..\common\drivers\com_os
    hpzimv12.dll=1,..\..\..\common\drivers\com_os
    hpzjui12.dll=1,..\..\..\common\drivers\com_os
    hpzl3212.dll=1,..\com_lang
    hpzl9x12.dll=1,..\..\..\common\drivers\win9x_me
    hpzlje12.dll=1,..\..\..\common\drivers\com_os
    hpzlnt12.dll=1,..\..\..\common\drivers\win2k_xp
    hpzntk12.dll=1,..\..\..\common\drivers\win2k_xp
    hpzntp12.dll=1,..\..\..\common\drivers\win2k_xp
    hpzpcl12.dll=1,..\..\..\common\drivers\com_os
    hpzpip12.dll=1,..\..\..\common\drivers\com_os
    hpzpm112.dll=1,..\..\..\common\drivers\win9x_me
    hpzpm312.dll=1,..\..\..\common\drivers\win2k_xp
    hpzpnp12.dll=1,.
    hpzpre12.exe=1,..\..\..\common\drivers\com_os
    hpzr3212.dll=1,..\com_lang
    hpzres12.dll=1,..\..\..\common\drivers\com_os
    hpzrm112.dll=1,..\com_lang
    hpzrm312.dll=1,..\com_lang
    hpzrp112.dll=1,..\..\..\common\drivers\win9x_me
    hpzrp312.dll=1,..\..\..\common\drivers\win2k_xp
    hpzs9x12.dll=1,..\..\..\common\drivers\win9x_me
    hpzslk12.dll=1,..\..\..\common\drivers\com_os
    hpzsnt12.dll=1,..\..\..\common\drivers\win2k_xp
    hpzsta9x.exe=1,..\..\..\common\drivers\win9x_me
    hpzstc12.exe=1,..\..\..\common\drivers\com_os
    hpzstsin.dll=1,..\..\..\common\drivers\win9x_me
    hpzstw12.exe=1,..\..\..\common\drivers\com_os
    hpztbi12.dll=1,..\..\..\common\drivers\com_os
    hpztbu12.exe=1,..\..\..\common\drivers\com_os
    hpztbx12.exe=1,..\..\..\common\drivers\com_os
    hpzvip12.dll=1,..\..\..\common\drivers\com_os
    hppapml0.dll=1,..\..\..\common\drivers\com_os
    hpbmiapi.dll=1,..\..\..\common\drivers\com_os
    hpboidPS.dll=1,..\..\..\common\drivers\com_os
    hpbproPS.dll=1,..\..\..\common\drivers\com_os
    hpjcmn2u.dll=1,..\..\..\common\drivers\com_os
    hpjipx1u.dll=1,..\..\..\common\drivers\com_os
    hpboid.exe=1,..\..\..\common\drivers\com_os
    hpbpro.exe=1,..\..\..\common\drivers\com_os
    atl.dll=1,..\..\..\common\drivers\win9x_me
    usbmon.dll=1

    Comment


    • #3
      Re: Script for installing local printers with TCP/IP port

      Originally posted by Iznogoud View Post
      Like Rob van der Woude is explaining in his script i can find the names out the .INF file, but i can't!

      See my 2nd post for the .INF driver of the Printer.

      I have find a script of Microsoft wich is based on VBS, but that script doesn't include a path to a driver

      Could someone help me with this script or if you have a working script wich adds a local printer that would also be good.
      Get the "Models" from the INF file => HP Deskjet 6600 Series


      sample of a vbscript:
      Code:
      PrnName = "Accounting 2nd Floor"
      PrnLocation = "2nd floor west, room 102"
      PrnComment = "Test printer script"
      PrnDrv = "HP Deskjet 6600 Series"
      DrvPath = "C:\HPDJ6600\enu\drivers\win2k_xp"
      InfPath = DrvPath & "\hpf6600k.inf"
      PortIP = "192.168.1.223"
      PortName = "IP_" & PortIP
      
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:" _
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      
      ''''''''''''''''''''''''''
      ' create ip-printer-port
      ''''''''''''''''''''''''''
      Set objNewPort = objWMIService.Get _
          ("Win32_TCPIPPrinterPort").SpawnInstance_
      
      objNewPort.Name = PortName
      objNewPort.Protocol = 1
      objNewPort.HostAddress = PortIP
      objNewPort.PortNumber = "9100"
      objNewPort.SNMPEnabled = False
      objNewPort.Put_
      
      ' wsh.echo "port created"
      
      ''''''''''''''''''''''''''
      ' install printer driver
      ''''''''''''''''''''''''''
      ' If the driver is not signed, one cannot use WMI scripting
      ' to install the driver. 
      ' Make sure the cat file for the package is copied to the same
      ' location as the driver 
      
      objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
      
      Set objDriver = objWMIService.Get("Win32_PrinterDriver")
      
      objDriver.Name = PrnDrv
      objDriver.SupportedPlatform = "Windows NT x86"
      objDriver.Version = "3"
      objDriver.DriverPath = DrvPath
      objDriver.Infname = InfPath
      intResult = objDriver.AddPrinterDriver(objDriver)
      
      ' wsh.echo "driver installed"
      
      ''''''''''''''''''''''''''
      ' Add local printer
      ''''''''''''''''''''''''''
      Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
      
      objPrinter.DriverName = PrnDrv
      objPrinter.PortName = PortName
      objPrinter.DeviceID = PrnName
      objPrinter.Location = PrnLocation
      objPrinter.Comment = PrnComment
      objPrinter.Network = True
      objPrinter.Put_
       
      ' wsh.echo "printer added"
      
      'optional:
      ''''''''''''''''''''''''''
      ' Stop & Start Printer Spooler
      ''''''''''''''''''''''''''
      Set objSpoolerSvc = objWMIService.Get("Win32_Service.Name='spooler'")
      iReturn = objSpoolerSvc.StopService()
      iReturn = objSpoolerSvc.StartService()
      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Script for installing local printers with TCP/IP port

        The funniest thing is that i did check the models section and tried almost all the names in the .INF file even the HP Deskjet 6600 Series, but it still didn't work.
        But in the other hand your script is working great.

        No errors if the port excist or not, no errors if the printer excist. It just installs the printer and thats it.



        PS. Are you a programmer or did you make this with some kind WMI Scripting tool?

        Originally posted by Rems View Post
        Get the "Models" from the INF file => HP Deskjet 6600 Series


        sample of a vbscript:
        Code:
        PrnName = "Accounting 2nd Floor"
        PrnLocation = "2nd floor west, room 102"
        PrnComment = "Test printer script"
        PrnDrv = "HP Deskjet 6600 Series"
        DrvPath = "C:\HPDJ6600\enu\drivers\win2k_xp"
        InfPath = DrvPath & "\hpf6600k.inf"
        PortIP = "192.168.1.223"
        PortName = "IP_" & PortIP
        
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        
        ''''''''''''''''''''''''''
        ' create ip-printer-port
        ''''''''''''''''''''''''''
        Set objNewPort = objWMIService.Get _
            ("Win32_TCPIPPrinterPort").SpawnInstance_
        
        objNewPort.Name = PortName
        objNewPort.Protocol = 1
        objNewPort.HostAddress = PortIP
        objNewPort.PortNumber = "9100"
        objNewPort.SNMPEnabled = False
        objNewPort.Put_
        
        ' wsh.echo "port created"
        
        ''''''''''''''''''''''''''
        ' install printer driver
        ''''''''''''''''''''''''''
        ' If the driver is not signed, one cannot use WMI scripting
        ' to install the driver. 
        ' Make sure the cat file for the package is copied to the same
        ' location as the driver 
        
        objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
        
        Set objDriver = objWMIService.Get("Win32_PrinterDriver")
        
        objDriver.Name = PrnDrv
        objDriver.SupportedPlatform = "Windows NT x86"
        objDriver.Version = "3"
        objDriver.DriverPath = DrvPath
        objDriver.Infname = InfPath
        intResult = objDriver.AddPrinterDriver(objDriver)
        
        ' wsh.echo "driver installed"
        
        ''''''''''''''''''''''''''
        ' Add local printer
        ''''''''''''''''''''''''''
        Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
        
        objPrinter.DriverName = PrnDrv
        objPrinter.PortName = PortName
        objPrinter.DeviceID = PrnName
        objPrinter.Location = PrnLocation
        objPrinter.Comment = PrnComment
        objPrinter.Network = True
        objPrinter.Put_
         
        ' wsh.echo "printer added"
        
        'optional:
        ''''''''''''''''''''''''''
        ' Stop & Start Printer Spooler
        ''''''''''''''''''''''''''
        Set objSpoolerSvc = objWMIService.Get("Win32_Service.Name='spooler'")
        iReturn = objSpoolerSvc.StopService()
        iReturn = objSpoolerSvc.StartService()
        \Rems

        Comment

        Working...
        X