lpenrod
asked on
Batch file help
I need help creating a batch file.
I will create a file called printerlist.txt that has a list of printers and looks something like this:
\\server\printername1
\\server\printername2
\\server\printername3
I have a command line utility called ADPRINTX (http://www.jsiinc.com/SUBM/tip6000/rh6065.htm) that is used to install remote printers from the command line.
I would like the batch file to dynamically create a list similar to below:
1. printername1
2. printername2
3. printername3
I would like the batch file to prompt the user asking which printer to make the default printer. Then I would like every printer in the list installed with the appropriate one being set as the default.
Here is the syntax for ADPRINTX
adprintx /c "\\server\printername" (this adds a printer)
adprintx /cd "\\server\printername" (this adds a printer and makes it the default)
Thanks!
I will create a file called printerlist.txt that has a list of printers and looks something like this:
\\server\printername1
\\server\printername2
\\server\printername3
I have a command line utility called ADPRINTX (http://www.jsiinc.com/SUBM/tip6000/rh6065.htm) that is used to install remote printers from the command line.
I would like the batch file to dynamically create a list similar to below:
1. printername1
2. printername2
3. printername3
I would like the batch file to prompt the user asking which printer to make the default printer. Then I would like every printer in the list installed with the appropriate one being set as the default.
Here is the syntax for ADPRINTX
adprintx /c "\\server\printername" (this adds a printer)
adprintx /cd "\\server\printername" (this adds a printer and makes it the default)
Thanks!
ASKER
Thanks, I will check it out!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Make sure you change the line (from my post)
set plistfile=printerlist.txt
to point to the location of your list file. Include drive info if necessary such as "c:\files\printerlist.txt" . . .
--
mrdtn
set plistfile=printerlist.txt
to point to the location of your list file. Include drive info if necessary such as "c:\files\printerlist.txt"
--
mrdtn
Also, avoid a path or filename containing spaces. The for loop will choke otherwise.
--
mrdtn
--
mrdtn
ASKER
You rock, that is exactly what I wanted, thanks!
--
mrdtn
--
:init
@echo off
setlocal enabledelayedexpansion
set plistfile=printerlist.txt
set /a counter=0
echo. & echo The following printers are specified: & echo.
for /f "tokens=*" %%r in (%plistfile%) do (
set /a counter+=1
set tok=%%r
set tok=!tok:\= !
call :getpname !tok!
echo !counter!. !printername!
)
echo.
:prompt
set /p defnum=Please select the number of the printer to be the default printer:
set /a defnum=%defnum%
if %defnum% leq 0 goto :prompt
if %defnum% gtr %counter% goto :prompt
:main
set /a counter=0
for /f "tokens=*" %%r in (%plistfile%) do (
set /a counter+=1
if !counter! equ %defnum% (
adprintx /cd %%r
echo Printer %%r is now the default printer.
) else (
adprintx /c %%r
)
)
pause
goto :eof
:getpname
:loop
set printername=%1
shift
if not %1.==. goto :loop
goto :eof