• 0

[Batch] How can I avoid/ignore Windows messages caused by the program?


Question

Hi,

I'm working on a Batch file to automatically remove old printers and install new drivers. It all works very well, except when the printers I want to remove are already gone. Windows will pop up and error that the printer is gone or can't be found and the program won't continue until the message is answered. I can't even click on the cmd prompt because the error has priority.

I don't care if the printer wasn't there. If that's the case, I want the program to move on.

I'm new to batch files, though. I'm not a practiced programmer either. Is there some sort of error handling that can answer Windows prompts or ignore them?

@ECHO OFF

:: Delete the HP P1006.
ECHO Deleting HP P1006 Printer........
rundll32 printui.dll,PrintUIEntry /dl /n "HP LaserJet P1006" /c\\%ComputerName%


:: Delete the Lexmark.
ECHO Deleting Lexmark Optra E+ Printer........
rundll32 printui.dll,PrintUIEntry /dl /n "Lexmark Optra E+ (MS)" /c\\%ComputerName%


:: Install the drivers.
ECHO Installing New HP P1006 Printer Drivers........
rundll32 printui.dll,PrintUIEntry /if /b "HP LaserJet P1006" /c\\%ComputerName% /f "C:\Temp\P1006_Install_Light\hpljp1005.inf" /r "USB001" /m "HP LaserJet P1006" 

:: Stop and Start the print spoolers so a restart is not neccessary.
ECHO Stopping and Start Print Spooler.........
net stop spooler

net start spooler

exit

2 answers to this question

Recommended Posts

  • 0

Have you tried adding /q ("Quiet") switch to your command?

Like:

rundll32 printui.dll,PrintUIEntry /q /dl /n "HP LaserJet P1006" /c\\%ComputerName%

You can execute rundll32 printui.dll,PrintUIEntry /? to see all available switches.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.