• 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.
  • Posts

    • The best thing would be to just allow more options to let users pick the layout they like, it doesn't matter at this point really and it's not that hard to do as evidenced but all the 3rd party menus/tools that let you change it in lots of different ways. If you give the users more options they'll be happy, take them away and you have a problem.
    • They could've done that the very next day or from the start but when Win11 came out, the MSN team was still rooted in the OS division and pushing for it's hooks into everything. That's why we have recommended and all the MSN feed stuff in the widget panel which you also couldn't turn off at the start. Now that they've been pushed out, last I checked, all this MSN/web feed junk is finally getting the option to be turned off. tl/dr, it's not about coding ability, it's just dumb business decisions.
    • The headline doesn't fit the article. Sure the headline is more enticing probably, but come on, man. Keep it real, if you can help it.
    • The console sales don't mean much like they used to. Sony tells you this themselves but you seem to miss it. They care more about MAUs and how many people they can milk each month than x number of consoles sold, often to the more casual COD, Madden or FiFA gamers who play little else. Sony can't seem to port their games to the PC fast enough because they're not getting enough out of that 75 million console sales it seems. The traditional home console market has stagnated already, everyone knows it.
    • That is fair, I meant the comment somewhat whimsically and as such was a bit careless with the facts. Had I said either 2 or 4 that would be more defensible. SpaceX's Starship crashed 2 times during hop tests and 2 additional hop-test failures that while not exactly a "crash," still resulted in the total destruction of the test vehicle. Even in that example, it would still be fair for you to point out that Starship is a significantly more complex test vehicle and that SpaceX never crashed a simple rocket hop-test like this one. I already admitted that I could have been clearer, but I also don't think it unreasonable to use the word "it" when referring to the subject of the article I am commenting on. I feel like it is an outlying read of my words to assume "it" meant SpaceX's total success. Like I said, I accept responsibility for the ambiguity.
  • Recent Achievements

    • Week One Done
      slackerzz earned a badge
      Week One Done
    • Week One Done
      vivetool earned a badge
      Week One Done
    • Reacting Well
      pnajbar earned a badge
      Reacting Well
    • Week One Done
      TBithoney earned a badge
      Week One Done
    • First Post
      xuxlix earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      681
    2. 2
      ATLien_0
      285
    3. 3
      Michael Scrip
      225
    4. 4
      +FloatingFatMan
      197
    5. 5
      Steven P.
      136
  • Tell a friend

    Love Neowin? Tell a friend!