When I run an app from the cmd-line, how do I find the exe's path?

When I run an app from the DOS Prompt in Windows, the command in question is often not in the current directory, but is found via the PATH environment variable. What's the quickest way to find the path of the actual EXE that's being run?


Solution 1:

On Vista you can type the executable's name in search field in start menu, when it's displayed in results, r-click and select "Open file location" from menu.

If the program is still running and you are using Process explorer from Sysinternals you can r-click on executable in the the processes list and select properties. In the Image tab you have path to the executable.

Another way is to use Windows Powershell, use command "get-command executable" without quotes and you will get path for the executable you are looking for. Shortcut for the command is gcm, so use like this "gcm calc"

Solution 2:

If you have cygwin installed, you could always use the 'which' command

C:> which notepad
/c/WINDOWS/system32/notepad

Solution 3:

Try the following:

@rem file which.bat (must be placed somewhere in %PATH%)
@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

When you type which notepad in commandline (cmd.exe):

C:\>which notepad
C:\Windows\System32\notepad.exe

Solution 4:

If you're asking about a program currently running, Windows doesn't offer anything out-of-the-box for the command line, as far as I'm aware, that gives you the full path of the executable.

If you're asking about a program that you are able to invoke at the command line, then you can use the where command:

C:\> where fsutil
C:\Windows\System32\fsutil.exe

C:\>

This works for all programs that you can invoke in your current PATH variable or the current working directory. It won't detect built-in commands such as DIR, but that's to be expected.