Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for expprndr.bat

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

  1. @ECHO OFF
  2. :: Check Windows version and command line argument(s)
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4. IF     "%~1"=="" GOTO Syntax
  5. IF NOT "%~2"=="" GOTO Syntax
  6.  
  7. :: Localize variables and enable delayed variable expansion
  8. SETLOCAL ENABLEDELAYEDEXPANSION
  9.  
  10. :: Check if DEVCON.EXE is available and if not, offer to download it
  11. SET DevconAvailable=
  12. SET Download=
  13.  
  14. DEVCON.EXE /? >NUL 2>&1
  15. IF ERRORLEVEL 1 (
  16. 	SET DevconAvailable=No
  17. 	ECHO This batch file requires Microsoft's DEVCON untility.
  18. 	SET /P Download=Do you want to download it now? [y/N] 
  19. )
  20.  
  21. :: Start download if requested
  22. IF /I "%Download%"=="Y" (
  23. 	START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
  24. 	ECHO.
  25. 	ECHO Install the downloaded file and make sure DEVCON.EXE is in the PATH.
  26. 	ECHO Then try again.
  27. )
  28.  
  29. :: Abort if DEVCON.EXE is not available yet
  30. IF "%DevconAvailable%"=="No" (
  31. 	ENDLOCAL
  32. 	GOTO:EOF
  33. )
  34.  
  35. :: Check how many matching printers are found, if any
  36. FOR /F %%A IN ('DEVCON Find ^=Printer "%~1*" 2^>NUL ^| FIND.EXE /C "\"') DO SET Matches=%%A
  37. IF %Matches% EQU 0 (
  38. 	CLS
  39. 	ECHO.
  40. 	ECHO ERROR: Specified printer not found
  41. 	GOTO Syntax
  42. )
  43. IF %Matches% GTR 1 ECHO %Matches% matching printers found
  44.  
  45. :: Create a directory the driver files will be copied to
  46. MD "%~1" >NUL 2>&1
  47.  
  48. :: Create a batch file "install_driver.bat" to (re)install the driver(s)
  49. >  "%~1\install_driver.bat" ECHO :: Batch file generated by ExpPrnDr.bat (Export Printer Drivers),
  50. >> "%~1\install_driver.bat" ECHO :: written by Rob van der Woude, http://www.robvanderwoude.com
  51. >> "%~1\install_driver.bat" ECHO PUSHD "%%~dp0"
  52.  
  53. :: Create an empty readme.txt
  54. TYPE NUL > "%~1\readme.txt"
  55.  
  56. :: Find and copy the driver files for the specified printer(s),
  57. :: and append the install command(s) to "install_driver.bat"
  58. FOR /F "tokens=1-5*" %%A IN ('DEVCON DriverFiles ^=Printer "%~1*"') DO (
  59. 	IF "%%~B"=="" (
  60. 		COPY /Y "%%~A" "%~1\" >NUL
  61. 	) ELSE (
  62. 		IF /I "%%~A"=="Name:" (
  63. 			SET Model=%%~B %%~C %%~D %%~E %%~F
  64. 			>> "%~1\readme.txt" ECHO.%%~A !Model!
  65. 		)
  66. 		IF /I "%%~A %%~B %%~C"=="Driver installed from" (
  67. 			COPY /Y "%%~D" "%~1\" >NUL
  68. 			SET Inf=%%~nxD
  69. 			>> "%~1\readme.txt" ECHO.%%~A %%~B %%~C !Inf! %%~E
  70. 			>> "%~1\install_driver.bat" ECHO :: The following line will install the printer driver for the !Model!
  71. 			>> "%~1\install_driver.bat" ECHO RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /ia /b"!Model!" /f"%%~dp0!Inf!" /m"!Model!"
  72. 		)
  73. 	)
  74. )
  75.  
  76. :: Close readme.txt
  77. >> "%~1\readme.txt" ECHO Install the driver with install_driver.bat
  78.  
  79. :: Close install_driver.bat
  80. >> "%~1\install_driver.bat" ECHO POPD
  81.  
  82. ECHO.
  83. ECHO The printer driver files for the "%Model%" printer
  84. ECHO are copied to the "%~dp0%~1" folder.
  85. ECHO.
  86. ECHO Use install_driver.bat, located in that folder, to (re)install the driver.
  87.  
  88. ENDLOCAL
  89. GOTO:EOF
  90.  
  91. :Syntax
  92. ECHO.
  93. IF     "%Matches%"=="0" ECHO ExpPrnDr.bat (Export Printer Drivers),  Version 1.01 for Windows 2000 / XP
  94. IF NOT "%Matches%"=="0" ECHO ExpPrnDr.bat,  Version 1.01 for Windows 2000 / XP
  95. IF NOT "%Matches%"=="0" ECHO Export Printer Drivers
  96. ECHO.
  97. ECHO Usage:  EXPPRNDR  printer
  98. ECHO.
  99. ECHO Where:  "printer"  is (the first part of) the printer name, e.g. "Epson"
  100. ECHO.
  101. ECHO Notes:  This batch file will copy all the files of the specified printer driver
  102. ECHO         to a newly created directory with the specified printer name.
  103. ECHO         This batch file can be used for local printers only.
  104. ECHO         The specified local printer(s) must be connected and switched on.
  105. ECHO         This batch file requires Microsoft's DEVCON to create a list of driver
  106. ECHO         files. If DEVCON is not available, you will be prompted to download it.
  107. ECHO         A batch file "install_driver.bat" will be created in the driver files
  108. ECHO         directory; use that batch file to (re)install the printer driver(s).
  109. ECHO         If multiple printers match the specified name, their drivers will all
  110. ECHO         be stored in a single directory, and "install_driver.bat" will
  111. ECHO         (re)install them all.
  112. ECHO.
  113. ECHO Written by Rob van der Woude
  114. ECHO http://www.robvanderwoude.com
  115.  
  116. IF "%OS%"=="Windows_NT" ENDLOCAL
  117. IF "%OS%"=="Windows_NT" COLOR 00
  118.  

page last uploaded: 2017-08-21, 14:26