This script will check to see if a certian printer is installed. If it is not installed it will install it. If it is installed it will move on.

Since I am new to scripting, It drove me nuts trying to find a script that does this. So thsi is for all the newbs.

Also All you need to do with this script is change the server and newprinter vars to suit your needs.


Questions or comments are welcome. Enjoy!

Code:

; This script checks for the existence of a printer
; if the printer does not exists then it installs a new printer

break on
$server = "yourserver"
$newprinter = "yourprinter"
$localkey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers"
$sep = "\"
$Index = 0
:Loop1
$PRINTER = ENUMKEY ($localkey,$Index)
;$PORT=ENUMVALUE ("$localkey\$PRINTER",5)
$KeyName=READVALUE ("$localkey\$PRINTER","PORT")
If @ERROR = 0
? "Name found: $KeyName"
$lenkey = len($keyname)
$keyname = substr($keyname,3,$lenkey - 2)
$comma = instr($keyname,$sep)
$servername = substr($keyname,1,$comma-1)
$Printer = substr($keyname,$comma+1,$lenkey - $comma - 1)
" Server = $Servername, Printer = $printer"
if $printer = ""
GOTO Installprinter
endif
if $printer = $newprinter
GOTO End
endif
$Index = $Index + 1
goto Loop1
Endif
:Installprinter
RUN "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter"
? "Please Wait"
sleep 3
sendkeys("{ENTER}")
sendkeys("~N")
sendkeys("{ENTER}")
sleep 1
sendkeys("~P")
sendkeys("\\$server\$newprinter")
sleep 1
sendkeys("~N")
sendkeys("{ENTER}")
sendkeys("{TAB}")
sendkeys("{TAB}")
sendkeys("{ENTER}")
sendkeys("~N")
sendkeys("{ENTER}")
sleep 3

:End



Props to Mystic Mike whom I stole the Loop segment of thsi code from.