Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CD %SystemDrive%\Windows\System32
- CLS
- :: Explanation of variables below.
- :: varIP - This is the IP of the printer.
- :: varDriver - This is the display name of the driver. THIS IS VERY IMPORTANT TO GET CORRECT!!!
- :: You get this info from the INF file (the driver file). Open the INF in a text editor and search for it.
- :: Each INF is different so it's hard to explain how to find this.
- :: An alternative method is to start the install of the printer on your machine, select the INF, and on the next screen
- :: the display name is given. THIS MUST BE EXACT OR THE PRINTER WILL NOT INSTALL.
- ::
- :: If you're using two different INF's, one for 7 and one for XP, the display name may be different for each INF.
- :: If that is the case, you'll need to create a varDriverXP variable and give it the proper display name. You'll then need
- :: to make the appropriate changes in the XP portion of the script below.
- :: So far I have not run into this, but wanted to warn you.
- :: varDriverFile7 - Path to the Windows 7 driver. There can be spaces in the path. DO NOT include quotes.
- :: varDriverFileXP - Path to the Windows XP driver. There can be spaces in the path. DO NOT include quotes.
- :: varName - The display name of the printer AFTER installation.
- :: varLocation - This is optional, as it only sets the Location field of the printer.
- SET varIP=X.X.X.X
- SET varDriver=HP LaserJet P2015 Series PCL 6
- SET varDriverFile7=\\server\path-to-drivers\Win7\hppcp604.inf
- SET varDriverFileXP=\\server\path-to-drivers\XP\hppcp604.inf
- SET varName=HP P2015
- SET varLocation=Building 1 Lab 10
- :: Determine OS
- If exist "c:\Users\Default\NTUSER.DAT" goto Win7
- If exist "c:\Documents and Settings\All Users\NTUSER.DAT" goto WinXP
- :WinXP
- cls
- Echo Installing printer in Windows XP
- :: Printer deletion - Optional
- :: Delete existing printer if trying to add printer with the same name.
- CSCRIPT /nologo %windir%\System32\prnmngr.vbs -d -p "%varName%"
- :: Deleting TCP/IP port
- CSCRIPT /nologo %windir%\System32\prnport.vbs -d -r IP_%varIP%
- :: Creating TCP/IP port
- CSCRIPT /nologo %windir%\System32\prnport.vbs -a -r IP_%varIP% -h %varIP% -o RAW -n 9100
- :: Driver installation
- rundll32 printui.dll,PrintUIEntry /if /b "%varName%" /f "%varDriverFileXP%" /r "IP_%varIP%" /m "%varDriver%"
- rundll32 printui.dll,PrintUIEntry /ia /K /m "%varDriver%" /h "Windows NT x86" /v 3 /f "%varDriverFileXP%"
- :: Location configuration - Optional
- CSCRIPT /nologo %windir%\System32\prncnfg.vbs -t -p "%varName%" -l "%varLocation%"
- :: Set as default printer - Optional
- CSCRIPT /nologo %windir%\System32\prnmngr.vbs -t -p "%varName%"
- goto Exit
- :Win7
- cls
- Echo Installing printer in Windows 7
- :: Printer deletion - Best practice
- :: Delete existing printer if trying to add printer with the same name.
- CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "%varName%"
- :: Deleting TCP/IP port
- CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -d -r IP_%varIP%
- :: Creating TCP/IP port
- CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r IP_%varIP% -h %varIP% -o RAW -n 9100
- :: Driver installation
- cscript /nologo %windir%\System32\Printing_Admin_Scripts\en-US\Prndrvr.vbs -a -m "%varDriver%" -v 3 -e "Windows NT x86" -i "%varDriverFile7%"
- :: Printer installation
- CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a -p "%varName%" -m "%varDriver%" -r "IP_%varIP%"
- :: Location configuration - Optional
- CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs -t -p "%varName%" -l "%varLocation%"
- :: Set as default printer - Optional
- CSCRIPT /nologo %windir%\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p "%varName%"
- goto Exit
- :Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement