Powered by GeSHi

Source code for addipprn.bat

(view source code of addipprn.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. SETLOCAL
  5.  
  6. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  7. ::                                                                         ::
  8. ::    Modify the following lines; no quotes for PrnShort and PortIP!       ::
  9. ::                                                                         ::
  10. ::    The values for PrnType and TargetOS can be found in the INF file     ::
  11. ::    that comes with the (extracted) printer driver.                      ::
  12. ::                                                                         ::
  13. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  14.  
  15. SET PrnName="Accounting 2nd Floor"
  16. SET PrnShort=Accounting2
  17. SET PrnType="Kyocera Mita FS-3820N"
  18. SET DrvPath="\\server\share\Drivers\Kyocera\FS-3820N\W2K"
  19. SET InfPath="\\server\share\Drivers\Kyocera\FS-3820N\W2K\oemsetup.inf"
  20. SET PortIP=112.113.114.115
  21. SET TargetOS="Windows 2000"
  22.  
  23. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  24. ::                                                                         ::
  25. ::       End of adjustments                                                ::
  26. ::                                                                         ::
  27. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  28.  
  29. :: Check command line arguments
  30. IF "%~1"=="" GOTO Syntax
  31. SET PC=%~1
  32. ECHO."%PC%" | FINDSTR.EXE /R /C:"[?/]" >NUL && GOTO Syntax
  33. PING.EXE %PC% 2>NUL | FIND.EXE  "TTL=" >NUL || (
  34. 	ECHO Computer %PC% is unavailable
  35. 	ECHO.
  36. 	GOTO Syntax
  37. )
  38.  
  39. :: Check if the required VBScripts are available in the current directory
  40. SET Error=0
  41. FOR %%A IN (prncfg prnmgr drvmgr portmgr) DO IF NOT EXIST %%A.vbs SET Error=1
  42. IF "%Error%"=="1" GOTO Syntax
  43.  
  44. :: Check if the printer was installed already
  45. CSCRIPT.EXE //NoLogo prnmgr.vbs -l -c \\%PC% | FIND.EXE /I "%PrnShort%" >NUL && (
  46. 	ECHO A printer named %PrnShort% already exists on %PC%
  47. 	ECHO.
  48. 	GOTO Syntax
  49. )
  50.  
  51. :: Check if the printer port was installed already
  52. CSCRIPT.EXE //NoLogo portmgr.vbs -l -c \\%PC% | FINDSTR.EXE /E /I "IP_%PortIP%" >NUL && (
  53. 	ECHO TCP/IP printer port %PortIP% already exists on %PC%
  54. 	ECHO.
  55. 	GOTO Syntax
  56. )
  57.  
  58. :: Prompt the user, and allow him/her to abort the installation
  59. ECHO You are about to add a local printer %PrnShort% on computer %PC%
  60. ECHO.
  61. PAUSE
  62.  
  63. :: Install the driver
  64. CSCRIPT.EXE //NoLogo drvmgr.vbs  -a -c \\%PC% -p %DrvPath% -i %InfPath% -v %TargetOS% -m %PrnType% -t Intel
  65. :: Install the local IP print port, type raw, SNMP disabled
  66. CSCRIPT.EXE //NoLogo portmgr.vbs -a -c \\%PC% -p IP_%PortIP% -h %PortIP% -t raw -n 9100 -md
  67. :: Install the local printer with the driver and port we just installed
  68. CSCRIPT.EXE //NoLogo prnmgr.vbs  -a -c \\%PC% -b %PrnName% -m %PrnType% -r IP_%PortIP%
  69. :: Configure the local printer as not shared and not published in Active Directory
  70. CSCRIPT.EXE //NoLogo prncfg.vbs  -s -b \\%PC%\%PrnShort% -published -shared
  71.  
  72. :: Display or log the configuration of the new printer
  73. IF /I "%~2"=="/L" (SET Log="%PrnShort%_%PC%.log") ELSE (SET Log=CON)
  74. (
  75. 	CSCRIPT.EXE //NoLogo drvmgr.vbs  -l -c \\%PC%
  76. 	CSCRIPT.EXE //NoLogo portmgr.vbs -l -c \\%PC%
  77. 	CSCRIPT.EXE //NoLogo prnmgr.vbs  -l -c \\%PC%
  78. 	CSCRIPT.EXE //NoLogo prncfg.vbs  -g -b \\%PC%\%PrnShort%
  79. ) > %Log% 2>&1
  80.  
  81. :: Done
  82. GOTO End
  83.  
  84. :Syntax
  85. ECHO.
  86. ECHO AddIPPrn.bat,  Version 1.01 for Windows 2000 with Server Resource Kit
  87. ECHO Install a (hard coded) local IP printer %PrnShort% on a remote computer
  88. ECHO.
  89. ECHO Usage:  ADDIPPRN.BAT   computername  [ /L ]
  90. ECHO.
  91. ECHO Where:  "computername" is the computer on which the printer should be installed
  92. ECHO         "/L"           logs the results in {printername}_{computername}.log
  93. ECHO                        (default is display on screen)
  94. ECHO.
  95. ECHO Notes:  [1] You need to modify the first couple of lines from this batch file
  96. ECHO             to install your own printer, port and driver. You may then want
  97. ECHO             to save the modified batch file as {printername}.bat.
  98. ECHO         [2] This batch file requires drvmgr.vbs, portmgr.vbs, prnmgr.vbs and
  99. ECHO             prncfg.vbs from the Windows 2000/2003 Server Resource Kit; these
  100. ECHO             scripts must all be located in the current directory.
  101. ECHO         [3] These VBScripts require PRNADMIN.DLL from the Resource Kit to be
  102. ECHO             installed on the computer that runs the scripts.
  103. ECHO.
  104. ECHO Written by Rob van der Woude
  105. ECHO http://www.robvanderwoude.com
  106.  
  107. :End
  108. IF "%OS%"=="Windows_NT" ENDLOCAL
  109.