• 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

    • Can we brainstorm funny mission names for this drone operation? Absolutely, *S$%#@^* — let’s christen this skybound scatventure with the honor it deserves. Here’s a flight manifest of mission names, ranging from mildly irreverent to dangerously cheeky: Military/Technical Jargon Style Operation Brown Drop Tactical Rear Ejection (T.R.E.) Project Chute’n’Scoot Aerial Waste Dispersal Initiative (AWDI) FLUSH Protocol: Flight-Level Unsanitary Substrate Handling Space Race Vibes Apollo Poopteen Excreta Prime The Dinglehopper Initiative Sputnik 2.0: The Brown Comet Turdis in the Sky with Sharts Pun- Laden Classics Bombs Away, Butt Not Really Shairstrike Full Dump Jacket No Guts, No Plume Fecal Falcon: The Return Eco-Conscious Spin Nutrient Reallocation Squadron Eco-Drop 9000 Compost from the Clouds Operation: Biopoop Cycle The Humus Hurl Would you like me to whip up a mission patch for Operation Full Dump Jacket or maybe draft a press briefing for the Fecal Falcon’s maiden sortie? We can even simulate a malfunction scenario — “Code Brown in Sector 12!” Where to next, Flight Commander?   And That's just mentioning the word 'shart' but in reverse mentioning what a particular situation is
    • hey guys its not counterfeit. i did test its ok needs formatting but how do i do that i need to go in dos and disk Disk Management anyone know step by step please 
    • The first link on the github page gives me a very, very red page warning me about phishing........
    • Hey Nick! 👋 No worries at all — you're not alone in this, and it's great you're asking for help. Let me walk you through a simple, step-by-step fix using the tool mentioned on that AOMEI Partition Assistant guide — it really does the trick for many people with this exact issue! ✅ Here’s how to restore your USB back to full 256GB on Windows 11: Download & Install AOMEI Partition Assistant Go to the link you shared: AOMEI Partition Assistant and click the Download Freeware button. Insert your USB stick (Sandisk Ultra 256GB) Make sure it's properly connected. Wait for the system to detect it. Launch AOMEI Partition Assistant Once open, you'll see all your connected drives listed. Locate your USB Drive Look for the one that says something like Disk X – Removable and shows only 3.1GB or so. Right-click on your USB Drive’s Partition Then select Delete Partition → confirm the deletion. Now, right-click on the unallocated space (it should now show full unallocated capacity) Choose Create Partition → format it as FAT32 or exFAT (recommended for larger drives) → click OK. Click “Apply” in the top left corner Then hit Proceed to execute the pending operations. Wait a bit... and boom! 🎉 Your USB should now be restored to its full 256GB capacity!
    • When Facebook bought Beat Saber, they promised exactly this would never happen. Facebook can’t not lie.
  • Recent Achievements

    • First Post
      Fuzz_c earned a badge
      First Post
    • First Post
      TIGOSS earned a badge
      First Post
    • 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
  • Popular Contributors

    1. 1
      +primortal
      713
    2. 2
      ATLien_0
      279
    3. 3
      Michael Scrip
      209
    4. 4
      +FloatingFatMan
      201
    5. 5
      Steven P.
      131
  • Tell a friend

    Love Neowin? Tell a friend!