I realized that space characters in the server path or printer name will not work with the above script, so I have provided a modified script below which properly handles these conditions.
Let me know if there are any questions.
--
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 call :getpname "%%r" 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 set tok2=%1 set tok2=%tok2:"=% :loop for /f "tokens=1,* delims=\" %%x in ("!tok2!") do ( set tok1=%%x set tok2=%%y ) if not "%tok2%"=="" goto :loop set printername=%tok1% goto :eof
|