batch file help. Using a list of printers

I have a batch that will get a list of printers installed on a local machine. The output is where my problem is. The batch gets the list and will print it to the screen, however in the for loop if there is a space or any other charactor after the %%a then the output wraps to the beginning of the line.

here is the output of the code below. I would like to pass the list into the for loop for use in creating printer config files....but it will not work with the current output.

OUTPUT:
C:\WINDOWS\system32>\temp\temp.bat
 SYCH-TECH
.datmp\PSYCH-TECHion file for PSYCH-TECH
 SYCH-RESIDENCY-DUPLEX
.datmp\PSYCH-RESIDENCY-DUPLEX PSYCH-RESIDENCY-DUPLEX
 SYCH-RESIDENCY
.datmp\PSYCH-RESIDENCYile for PSYCH-RESIDENCY
 SYCH-DCAP-COLOR-DUPLEX
.datmp\PSYCH-DCAP-COLOR-DUPLEXPSYCH-DCAP-COLOR-DUPLEX
 SYCH-DCAP-COLOR-BW-DUPLEX
.datmp\PSYCH-DCAP-COLOR-BW-DUPLEXCH-DCAP-COLOR-BW-DUPLEX
 SYCH-DCAP-COLOR-BW
.datmp\PSYCH-DCAP-COLOR-BWfor PSYCH-DCAP-COLOR-BW
 SYCH-DCAP-COLOR
.datmp\PSYCH-DCAP-COLORle for PSYCH-DCAP-COLOR
 SYCH-DCAP
.datmp\PSYCH-DCAPion file for PSYCH-DCAP

Here is the output of the wmic command:
C:\WINDOWS\system32>wmic /node:"%computername%" printer get name /value | findstr /i /c:"=" | findstr /i /v /c:"onenote" /c:"xps"  /c:"pdf"
Name=PSYCH-TECH
Name=PSYCH-RESIDENCY-DUPLEX
Name=PSYCH-RESIDENCY
Name=PSYCH-DCAP-COLOR-DUPLEX
Name=PSYCH-DCAP-COLOR-BW-DUPLEX
Name=PSYCH-DCAP-COLOR-BW
Name=PSYCH-DCAP-COLOR
Name=PSYCH-DCAP
@echo off

setlocal enableextensions enabledelayedexpansion

set printname=wmic /node:"%computername%" printer get name /value ^| findstr /i /c:"=" ^| findstr /i /v /c:"onenote"  /c:"xps"  /c:"pdf" 

for /f "delims== tokens=2" %%a in ( '!printname!' ) do (
	echo %%a 
	echo saving configuration file for %%a \temp\%%a.dat
	REM rundll32 printui.dll,printuientry /ss /n "%%a" /a "c:\temp\%%a.dat" g d
	)


endlocal

Open in new window

pphreadrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Give the attached a try, this is a work around for somewhat quirky formatting that WMIC does.  My approach is first to use the CSV output format from WMIC when I script, this elliminates some of the extra lines, and produces output that is easy to parse.  To see this in action try the following from a command line:

wmic /node:"%computername%" printer get name /value /format:csv

Notice that is does add the computer name as the first column all the time.

To get around the carriage return at the end of the line that WMIC returns, I just add a field to the GET after the field that I want, and then just grab the one field (token) that I am interested in in the FOR.  Also I skip the first line, since it is a field name line.

Let me know if this doesn't work, or doesn't make sense.

~bp


@echo off
 
setlocal enableextensions enabledelayedexpansion
 
set printname=wmic /node:"%computername%" printer get name^,workoffline /value /format:csv ^| findstr /i /v /c:"onenote" /c:"xps" /c:"pdf" 
 
for /f "skip=1 delims=, tokens=2" %%a in ( '!printname!' ) do (
        echo %%a 
        echo saving configuration file for %%a \temp\%%a.dat
        REM rundll32 printui.dll,printuientry /ss /n "%%a" /a "c:\temp\%%a.dat" g d
        )
 
endlocal

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pphreadrAuthor Commented:
I had to use 'skip=2', but worked great. thankx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.