How to test if an executable exists in the %PATH% from a windows batch file?

I’m looking for a simple way to test if an executable exists in the PATH environment variable from a Windows batch file.

Usage of external tools not provided by the OS is not allowed. The minimal Windows version required is Windows XP.


Windows Vista and later versions ship with a program called where.exe that searches for programs in the path. It works like this:

D:\>where notepad

D:\>where where

For use in a batch file you can use the /q switch, which just sets ERRORLEVEL and doesn’t produce any output.

where /q myapplication
    ECHO The application is missing. Ensure it is installed and placed in your PATH.
    EXIT /B
) ELSE (
    ECHO Application exists. Let's go!

Or a simple (but less readable) shorthand version that prints the message and exits your app:

where /q myapplication || ECHO Cound not find app. && EXIT /B

Source : Link , Question Author : sorin , Answer Author : Simon East

Leave a Comment