Disabling the “Windows cannot find ‘[foo].exe'” popups

Posted on

Problem :

When I use the start command in a batch script to launch a program, I expect that program to be launched asynchronously; this happens exactly as I’d expect it would if the program that I’m launching exists.

However, if I try to start a program that doesn’t exist, Windows displays a popup telling me that it cannot find the file, locking up the execution of the batch script until I manually close the popup. This is annoying. Because of some remote filesystem shenanigans, I have no way to reliably guarantee that the binary will exist before I run it, and I have no way to lock the binary. In my scenario, if the binary doesn’t exist, it’s not a critical error, and my script should just proceed.

Is there a way to prevent these popups from being created in the first place, or alternatively a batch/cmd one-liner that can be used to asynchronously execute applications that won’t block the script from continuing if it fails (something I can just as easily use from a CLI as a batch script)?

Solution :

I have no way to reliably guarantee that the binary will exist before I run it

You can use the which.cmd to see if a binary exists, and returns an appropriate ERRORLEVEL.


Workaround for your issue (Disabling the “Windows cannot find ‘[foo].exe'” popup)

  • run which program
  • check the ERRORLEVEL
  • run start only if program is found.
:: WHICH.CMD  CommandName  [ReturnVar]
::
::  Determines the full path of the file that would execute if
::  CommandName were executed.
::
::  The result is stored in variable ReturnVar, or else it is
::  echoed to stdout if ReturnVar is not specified.
::
::  If no file is found, then an error message is echoed to stderr.
::
::  The ERRORLEVEL is set to one of the following values
::    0 - Success: A matching file was found
::    1 - No file was found and CommandName is an internal command
::    2 - No file was found and CommandName is not an internal command
::    3 - Improper syntax - no CommandName specified

The link below includes the full source code for which.cmd (which was written by superuser user dbenham).

Source which.cmd – Show the full path to an executable file.

One way would be to copy/move the binary file to a new temporary location with a unique name and execute it.
If the copy/move is successful, then the unique file exists and you can execute it without influence from “remote filesystem shenanigans”.
If not, then at least you know you will not get the pop-up window.

Use the /C switch for the start command, it should skip the annoying popup.

start /C appthatmayfail.exe args

Leave a Reply

Your email address will not be published.