2

I've run into a printer problem (0x2 error) when trying to install printers in the office.

The solution is to run the Win7 pnputil -e > oem_list.txt Then remove all the oem*.inf files that are class 'Printers' Run GPUpate /Force to refresh Group Policy and logoff.

When you login, no more error and you can install printers from the server.

Sample output from PNPUtil -e

Microsoft PnP Utility

Published name :            oem0.inf  
Driver package provider :   Microsoft  
Class :                     Printers  
Driver date and version :   06/21/2006 6.1.7600.16385  
Signer name :               Microsoft Windows   

Published name :            oem1.inf  
Driver package provider :   Famatech  
Class :                     Display adapters  
Driver date and version :   08/08/2007 3.1  
Signer name :               Microsoft Windows Hardware Compatibility   Publisher

Published name :            oem2.inf  
Driver package provider :   Intel Corporation  
Class :                     System devices  
Driver date and version :   11/02/2006 1.0.0.0   
Signer name :               Microsoft Windows Hardware Compatibility   Publisher

Published name :            oem3.inf  
Driver package provider :   Microsoft  
Class :                     Printers  
Driver date and version :   06/21/2006 6.1.7601.17514  
Signer name :               Microsoft Windows  

I want to run "pnputil -f -d" on both oem0.inf and oem3.inf to remove them

I have tried several different BATCH loops using FOR /f and FINDSTR. For example:

for /f "tokens=1,3,4" %%a IN (oem_list.txt) do (  
    if %%a==Published (  
       set save_it=%%c  
     ) else (  
    if %%b==Printers pnputil -f -d %save_it%)  
     )  

However, even though save_it is set it is not -saved- by the time Class: Printers is found 2 lines down.

VERY Frustrating!

Please help!

Kevin Nagurski
  • 1,889
  • 11
  • 24
jmsallo
  • 21
  • 2
  • May be [this](http://stackoverflow.com/a/30177832/2861476) could explain the reason. – MC ND May 28 '15 at 16:02
  • possible duplicate of [set statements don't appear to work in my batch file](http://stackoverflow.com/questions/30177307/set-statements-dont-appear-to-work-in-my-batch-file) – Ken White May 28 '15 at 16:28
  • Ok, that explains in more detail what I've already discovered. However, it does NOT explain how to MAKE IT WORK. :( Surprising that something that is easy to code in C++ is so hard to do in a simple batch file. And I do have a working PowerShell script that loads the lines into an array. However, not every PC here has PS installed and creating an array of 100's of lines seems so terribly inefficient. – jmsallo May 28 '15 at 19:21
  • This one gave me the idea of saving the output to a file http://stackoverflow.com/questions/20484151/redirecting-output-from-within-batch-file?rq=1 – jmsallo May 28 '15 at 20:55

1 Answers1

0

This one works:

echo off
pnputil -e > oem_list.txt

for /f "tokens=1,3,4" %%a IN (oem_list.txt) do (
   if %%a==Published echo %%c > item.txt
   if %%b==Printers for /f %%a IN (item.txt) do (pnputil -f -d %%a))

DEL item.txt
DEL oem_list.txt
gpupdate /force /Logoff
jmsallo
  • 21
  • 2