Batch Script Help

Hi I am trying to write a batch file to delete old printers and drivers and add the new printers.

It all seems to be working fine except one thing.
Not all of the computers will have the universal print driver.  So the ones that don't have it generates an error which pops up on the screen.  I would like this to be seamless to the user, so if they don't have the driver instead of creating and error and generating a pop up I would like it to just skip it and go to installing the new printers.

Any help would be greatly appreciated.
REM Delete printers
 
rundll32 printui.dll,PrintUIEntry /dn /n\\PGDC01\PGPR01
rundll32 printui.dll,PrintUIEntry /dn /n\\PGDC01\PGPR02
rundll32 printui.dll,PrintUIEntry /dn /n\\PGDC01\PGPR03
 
 
REM Remove Printer Drivers for Plotter, 9500 & accounting
 
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP LaserJet P2015 Series PCL 5e" /h "Intel" /v "Windows 2000"
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Color LaserJet 9500 mfp PCL 6" /h "Intel" /v "Windows 2000"
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Designjet T1100 44in HPGL2" /h "Intel" /v "Windows 2000"
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Universal Printing PCL6" /h "Intel" /v "Windows 2000"
 
REM Add printers Plotter, 9500 & Accounting
 
rundll32 printui.dll,PrintUIEntry /in /n\\PGDC01\HP9500
rundll32 printui.dll,PrintUIEntry /in /n\\PGDC01\Accounting
rundll32 printui.dll,PrintUIEntry /in /n\\PGDC01\Plotter

Open in new window

utilitycoAsked:
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.

Britt ThompsonSr. Systems EngineerCommented:
You can try using an IF EXIST statement so it will only try to remove it if it's there:

if exist "filename" (
      goto DELDRIVER
      ) else (
      goto DONTDELDRIVER
      )

:DELDRIVER
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Universal Printing PCL6" /h "Intel" /v "Windows 2000"

:DONTDELDRIVER
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP LaserJet P2015 Series PCL 5e" /h "Intel" /v "Windows 2000"
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Color LaserJet 9500 mfp PCL 6" /h "Intel" /v "Windows 2000"
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Designjet T1100 44in HPGL2" /h "Intel" /v "Windows 2000"


In this case I'm not positive what the file name will be exactly but this should work if you can get that much
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
oBdACommented:
You can just add a /q to each command line for which you're not interested in an error message; /q (quiet) will suppress the error messages:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c\\%computername% /m "HP Universal Printing PCL6" /h "Intel" /v "Windows 2000" /q

Open in new window

0
utilitycoAuthor Commented:
Thanks to you both, used the first one for the driver error and use the second one for a different error with both the script is working perfect.  Thank you
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.