Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for addprint.bat

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

  1. @ECHO OFF
  2. VER | FIND "Windows 2000" >NUL
  3. IF ERRORLEVEL 1 GOTO Syntax
  4.  
  5. SETLOCAL
  6. SET Printer=%1
  7. SET RemotePC=%2
  8.  
  9. :: Check printer specified
  10. IF NOT DEFINED Printer GOTO Syntax
  11. IF NOT "%Printer:~0,2%"=="\\" GOTO Syntax
  12. FOR /F "tokens=1* delims=\" %%A IN ('ECHO.%Printer%') DO (
  13. 	SET PrintServer=%%A
  14. 	Set PrintShare=%%B
  15. )
  16. IF NOT DEFINED PrintShare GOTO Syntax
  17. PING %PrintServer% -n 1 -w 1000 2>&1 | FIND "TTL=" >NUL
  18. IF ERRORLEVEL 1 GOTO Syntax
  19. NET VIEW \\%PrintServer% 2>&1 | FIND /I "%PrintShare%" >NUL
  20. IF ERRORLEVEL 1 GOTO Syntax
  21.  
  22. :: Check remote PC if specified
  23. IF DEFINED RemotePC SET RemotePC=%RemotePC:\=%
  24. IF DEFINED RemotePC (
  25. 	PING %RemotePC% -n 1 -w 1000 2>&1 | FIND "TTL=" >NUL
  26. 	IF ERRORLEVEL 1 GOTO Syntax
  27. 	SET RemotePC=/C\\%RemotePC%
  28. )
  29.  
  30. :: Install the printer on the specified computer
  31. RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry /ga /n%Printer% %RemotePC%
  32. IF NOT ERRORLEVEL 1 ECHO Printer installed, please reboot %RemotePC%
  33.  
  34. ENDLOCAL
  35. GOTO:EOF
  36.  
  37. :Syntax
  38. ECHO.
  39. ECHO AddPrint.bat,  Version 1.01 for Windows 2000
  40. ECHO Install a network printer on any PC on the network
  41. ECHO.
  42. ECHO Usage:  ADDPRINT  \\print_server\printer_share  [ remote_pc ]
  43. ECHO.
  44. ECHO Where:              "print_server"   is the print server name or IP address
  45. ECHO                     "printer_share"  is the share name for the printer
  46. ECHO                     "remote_pc"      is the PC that will be using the
  47. ECHO                                      network printer -- default is local PC
  48. ECHO.
  49. ECHO Written by Rob van der Woude
  50. ECHO http://www.robvanderwoude.com
  51.  
  52. IF "%OS%"=="Windows_NT" ENDLOCAL
  53.  

page last modified: 2024-04-16; loaded in 0.0160 seconds