Created
December 26, 2012 15:44
-
-
Save dannymcc/4380985 to your computer and use it in GitHub Desktop.
This script, in it's current state, automates the process of creating a local IP port and installing the print driver. It runs locally on the machine that's installing the printer.
First, it checks if the client machine is running XP. If not, it assume Windows 7. There's a set of commands for XP, and a set of commands for Windows 7. The commands…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
echo **YOU MUST BE AN ADMINISTRATOR ON THIS MACHINE FOR THE SCRIPT TO WORK PROPERLY** | |
echo THIS SCRIPT WORKS FOR WINDOWS XP AND WINDOWS 7 | |
REM This determines if you're running XP or Windows 7 | |
ver | find "XP" > nul | |
if %errorlevel% == 1 goto :win7 | |
break | |
REM This runs if XP is found. The Windows 7 commands are at the bottom of this script | |
echo IDENTIFIED WINDOWS XP | |
echo Checking if printer "[PRINTER NAME HERE]" already exists | |
REM This command checks your registry for the printer you're installing. | |
REM The goto command only completes if the registry entry is found | |
set Key=hklm\system\controlset001\control\print\printers | |
reg query %Key%"\[PRINTER NAME HERE]" /v Name && goto :exists | |
break | |
REM This creates the local IP port for the printer's address | |
echo INSTALLING IP PRINTER PORT [PRINTER IP HERE] | |
cscript %windir%\system32\prnport.vbs -a -r "IP_[PRINTER IP HERE]" -h [PRINTER IP HERE] -o raw | |
REM This verifies the command completed successfully, otherwise it stops the script | |
if errorlevel 1 goto :end | |
break | |
echo INSTALLING PRINTER "[PRINTER NAME HERE]" | |
REM This uses the printui.dll to install the printer driver from the command line | |
rundll32 printui.dll,PrintUIEntry /if /r "IP_[PRINTER IP HERE]" /b "[PRINTER NAME HERE]" /f "[PATH TO THE PRINT DRIVER .INF FILE HERE].inf" /m "[SPECIFY THE DRIVER WITHIN THE INF FILE HERE]" | |
if errorlevel 0 goto :successful | |
if errorlevel 1 goto :error | |
:successful | |
break | |
break | |
echo THE PRINTER IS SUCCESSFULLY INSTALLED | |
pause | |
goto :end | |
pause | |
:error | |
break | |
break | |
echo ERRORS WERE FOUND. THE PRINTER DID NOT INSTALL | |
pause | |
goto :end | |
:exists | |
break | |
echo THE PRINTER ALREADY EXISTS. NO CHANGES WERE MADE. | |
pause | |
goto :end | |
REM These commands are the same as the commands above, but tailored for the differences in paths and | |
REM drivers for Windows 7 | |
:win7 | |
echo IDENTIFIED WINDOWS 7 | |
break | |
echo CHECKING IF PRINTER "[PRINTER NAME HERE]" already exists | |
set Key=hklm\system\controlset001\control\print\printers | |
reg query %Key%"\[PRINTER NAME HERE]" /v Name && goto :exists | |
break | |
echo INSTALLING IP PRINTER PORT [PRINTER IP HERE] | |
cscript %windir%\system32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r "IP_[PRINTER IP HERE]" -h [PRINTER IP HERE] -o raw | |
if errorlevel 1 goto :error | |
echo INSTALLING PRINTER "[PRINTER NAME HERE]" | |
rundll32 printui.dll,PrintUIEntry /if /r "IP_[PRINTER IP HERE]" /b "[PRINTER NAME HERE]" /f "[FULL PATH TO PRINTER DRIVER INF FILE].inf" /m "[SPECIFIC DRIVER IN THE INF FILE]" | |
if errorlevel 0 goto :successful | |
if errorlevel 1 goto :error | |
pause | |
:end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment