Batch File- Printer Driver in Windows 7

I have a batch file which is not working properly. What I am trying to do is to get Published name for the printer drivers by using pnputil -e command in windows 7.
I get : "no pattern match" at all the time.
for /f "tokens=1,2* delims=:" %%a in ('pnputil -e') do (
if %%a equ "Published name " (
set x=%%b
) else (
if %%a equ "Class " (
set test=%%b
set test=!test:~21!
if !test! equ Printers goto :setglob
)
)
)
echo "no pattern match"
goto :eof
:setglob
set x=%x: =%
set printers=%x%

Open in new window


Any thoughts, Thanks.
NetRock6Asked:
Who is Participating?
 
oBdACommented:
Try this then:
@echo off
setlocal enabledelayedexpansion
set ValPublishedName=Published name
set ValClass=Class
set ValProvider=Driver package provider
set ValVersion=Driver date and version
set ValSigner=Signer name
set ClassPrinters=Printers
echo Published names of 3rd party printer drivers:
set /a PrintLine = 0
for /f "tokens=1* delims=:" %%a in ('pnputil.exe -e') do (
	echo %%a|findstr.exe /i /b /c:"%ValPublishedName%" >NUL
	if not errorlevel 1 (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatPublishedName=%%u
	)
	echo %%a|findstr.exe /i /b /c:"%ValProvider%" >NUL
	if not errorlevel 1 (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatProvider=%%u
	)
	echo %%a|findstr.exe /i /b /c:"%ValVersion%" >NUL
	if not errorlevel 1 (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatVersion=%%u
	)
	echo %%a|findstr.exe /i /b /c:"%ValClass%" >NUL
	if not errorlevel 1 (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatClass=%%u
		if /i "!DatClass!"=="%ClassPrinters%" set /a PrintLine = 1
	)
	REM This is the last line per information block:
	echo %%a|findstr.exe /i /b /c:"%ValSigner%" >NUL
	if not errorlevel 1 (
		if "!PrintLine!"=="1" (
			echo !DatPublishedName! [!DatProvider!, !DatVersion!]
			set /a PrintLine = 0
		)
	)
)

Open in new window

0
 
oBdACommented:
For starters, this script would require "setlocal enabledelayedexpansion" in order for the expansion with "!" to work. Then it will only find the first occurrence of a third party driver file.
If the following script doesn't generate an output of all 3rd party printer driver files, please provide a sample output of "pnputil -e". Note that the script will currently not set a variable (like in your script), because you'd first need to define the required behavior if more than one 3rd party printer driver is present:
@echo off
setlocal enabledelayedexpansion
set ValPublishedName=Published name
set ValClass=Class
set ValProvider=Driver package provider
set ValVersion=Driver date and version
set ValSigner=Signer name
set ClassPrinters=Printers
echo Published names of 3rd party printer drivers:
set /a PrintLine = 0
for /f "tokens=1* delims=:" %%a in ('pnputil.exe -e') do (
	if /i not "%ValPublishedName%"=="!ValPublishedName:%%a=!" (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatPublishedName=%%u
	)
	if /i not "%ValProvider%"=="!ValProvider:%%a=!" (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatProvider=%%u
	)
	if /i not "%ValVersion%"=="!ValVersion:%%a=!" (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatVersion=%%u
	)
	if /i not "%ValClass%"=="!ValClass:%%a=!" (
		for /f "tokens=1*" %%t in ("_ %%~b") do set DatClass=%%u
		if /i "!DatClass!"=="%ClassPrinters%" (set /a PrintLine = 1)
	)
	REM This is the last line per information block:
	if /i not "%ValSigner%"=="!ValSigner:%%a=!" (
		if "!PrintLine!"=="1" (
			echo !DatPublishedName! [!DatProvider!, !DatVersion!]
			set /a PrintLine = 0
		)
	)
)

Open in new window

0
 
NetRock6Author Commented:
Hi oBda,

I used your script but still no output.
i do not get any errors but i get no output either too.
i just get:
"Published names of 3rd party printer drivers:"

with no published name...

Could please review code.

Thanks
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
oBdACommented:
As I said above: 'If the following script doesn't generate an output of all 3rd party printer driver files, please provide a sample output of "pnputil -e".'
0
 
NetRock6Author Commented:
ok. sorry about that...
i did copy/past but i guess did not work.

here second try:

Published name :            oem4.inf
Driver package provider :   Microsoft
Class :                     Printers
Driver date and version :   06/21/2006 6.1.7601.17514
Signer name :               Microsoft Windows
0
 
NetRock6Author Commented:
Wow,  Excellent job.....!
Keep it up .... Very Impressive!
Cheers, that works fantastically!
0
 
NetRock6Author Commented:
Cheers, that works fantastically!
Excellent +
Excellent  Solution!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.