Advertisement
Calvus

Add IP-based printer

Apr 10th, 2013
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CD %SystemDrive%\Windows\System32
  2.  
  3. CLS
  4.  
  5. :: Explanation of variables below.
  6. :: varIP - This is the IP of the printer.
  7. :: varDriver - This is the display name of the driver. THIS IS VERY IMPORTANT TO GET CORRECT!!!
  8. ::             You get this info from the INF file (the driver file). Open the INF in a text editor and search for it.
  9. ::             Each INF is different so it's hard to explain how to find this.
  10. ::             An alternative method is to start the install of the printer on your machine, select the INF, and on the next screen
  11. ::             the display name is given. THIS MUST BE EXACT OR THE PRINTER WILL NOT INSTALL.
  12. ::
  13. ::             If you're using two different INF's, one for 7 and one for XP, the display name may be different for each INF.
  14. ::             If that is the case, you'll need to create a varDriverXP variable and give it the proper display name. You'll then need
  15. ::             to make the appropriate changes in the XP portion of the script below.
  16. ::             So far I have not run into this, but wanted to warn you.
  17. :: varDriverFile7 - Path to the Windows 7 driver. There can be spaces in the path. DO NOT include quotes.
  18. :: varDriverFileXP - Path to the Windows XP driver. There can be spaces in the path. DO NOT include quotes.
  19. :: varName - The display name of the printer AFTER installation.
  20. :: varLocation - This is optional, as it only sets the Location field of the printer.
  21.  
  22. SET varIP=X.X.X.X
  23. SET varDriver=HP LaserJet P2015 Series PCL 6
  24. SET varDriverFile7=\\server\path-to-drivers\Win7\hppcp604.inf
  25. SET varDriverFileXP=\\server\path-to-drivers\XP\hppcp604.inf
  26. SET varName=HP P2015
  27. SET varLocation=Building 1 Lab 10
  28.  
  29. :: Determine OS
  30. If exist "c:\Users\Default\NTUSER.DAT" goto Win7
  31. If exist "c:\Documents and Settings\All Users\NTUSER.DAT" goto WinXP
  32.  
  33. :WinXP
  34. cls
  35. Echo Installing printer in Windows XP
  36. :: Printer deletion - Optional
  37. :: Delete existing printer if trying to add printer with the same name.
  38. CSCRIPT /nologo %windir%\System32\prnmngr.vbs -d -p "%varName%"
  39.  
  40. :: Deleting TCP/IP port
  41. CSCRIPT /nologo %windir%\System32\prnport.vbs -d -r IP_%varIP%
  42.  
  43. :: Creating TCP/IP port
  44. CSCRIPT /nologo %windir%\System32\prnport.vbs -a -r IP_%varIP% -h %varIP% -o RAW -n 9100
  45.  
  46. :: Driver installation
  47. rundll32 printui.dll,PrintUIEntry /if /b "%varName%" /f "%varDriverFileXP%" /r "IP_%varIP%" /m "%varDriver%"
  48. rundll32 printui.dll,PrintUIEntry /ia /K /m "%varDriver%" /h "Windows NT x86" /v 3 /f "%varDriverFileXP%"
  49.  
  50. :: Location configuration - Optional
  51. CSCRIPT /nologo %windir%\System32\prncnfg.vbs -t -p "%varName%" -l "%varLocation%"
  52.  
  53. :: Set as default printer - Optional
  54. CSCRIPT /nologo %windir%\System32\prnmngr.vbs -t -p "%varName%"
  55.  
  56. goto Exit
  57.  
  58. :Win7
  59. cls
  60. Echo Installing printer in Windows 7
  61. :: Printer deletion - Best practice
  62. :: Delete existing printer if trying to add printer with the same name.
  63. CSCRIPT /nologo  %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "%varName%"
  64.  
  65. :: Deleting TCP/IP port
  66. CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r IP_%varIP%
  67.  
  68. :: Creating TCP/IP port
  69. CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_%varIP% -h %varIP% -o RAW -n 9100
  70.  
  71. :: Driver installation
  72. cscript /nologo %windir%\System32\Printing_Admin_Scripts\en-US\Prndrvr.vbs -a -m "%varDriver%" -v 3 -e "Windows NT x86" -i "%varDriverFile7%"
  73.  
  74. :: Printer installation
  75. CSCRIPT /nologo  %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a -p "%varName%" -m "%varDriver%" -r "IP_%varIP%"
  76.  
  77. :: Location configuration - Optional
  78. CSCRIPT /nologo  %windir%\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs -t -p "%varName%" -l "%varLocation%"
  79.  
  80. :: Set as default printer - Optional
  81. CSCRIPT /nologo  %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p "%varName%"
  82.  
  83. goto Exit
  84.  
  85. :Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement