Finding the path of the program that will execute from the command line in Windows Finding the path of the program that will execute from the command line in Windows windows windows

Finding the path of the program that will execute from the command line in Windows


Use the where command. The first result in the list is the one that will execute.

C:\> where notepadC:\Windows\System32\notepad.exeC:\Windows\notepad.exe

According to this blog post, where.exe is included with Windows Server 2003 and later, so this should just work with Vista, Win 7, et al.

On Linux, the equivalent is the which command, e.g. which ssh.


As the thread mentioned in the comment, get-command in powershell can also work it out. For example, you can type get-command npm and the output is as below:

enter image description here


Here's a little cmd script you can copy-n-paste into a file named something like where.cmd:

@echo offrem - search for the given file in the directories specified by the path, and display the first matchremrem    The main ideas for this script were taken from Raymond Chen's blog:remrem         http://blogs.msdn.com/b/oldnewthing/archive/2005/01/20/357225.aspremremrem - it'll be nice to at some point extend this so it won't stop on the first match. That'llrem     help diagnose situations with a conflict of some sort.remsetlocalrem - search the current directory as well as those in the pathset PATHLIST=.;%PATH%set EXTLIST=%PATHEXT%if not "%EXTLIST%" == "" goto :extlist_okset EXTLIST=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH:extlist_okrem - first look for the file as given (not adding extensions)for %%i in (%1) do if NOT "%%~$PATHLIST:i"=="" echo %%~$PATHLIST:irem - now look for the file adding extensions from the EXTLISTfor %%e in (%EXTLIST%) do @for %%i in (%1%%e) do if NOT "%%~$PATHLIST:i"=="" echo %%~$PATHLIST:i