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

Zabba picture Zabba · Oct 23, 2010 · Viewed 103.8k times · Source

Say I have a program X.EXE installed in folder c:\abcd\happy\ on the system. The folder is on the system path. Now suppose there is another program on the system that's also called X.EXE but is installed in folder c:\windows\.

Is it possible to quickly find out from the command line that if I type in X.EXE which of the two X.EXE's will get launched? (but without having to dir search or look at the process details in Task Manager).

Maybe some sort of in-built command, or some program out there that can do something like this? :

detect_program_path X.EXE

Answer

Chris Schmich picture Chris Schmich · Oct 23, 2010

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

C:\> where notepad
C:\Windows\System32\notepad.exe
C:\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.