Question : 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!

Answer : Batch file help

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
Random Solutions  
 
programming4us programming4us