8

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?

1
  • 1
    "path" gives you a list, you could check each manually. Though don't absent mindedly hit ; before return, or you might have to spend 10 minutes rebuilding your path, like I just did >_<
    – Phoshi
    Sep 3, 2009 at 9:17

5 Answers 5

8

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"

2
  • 1
    Accepting this answer, as it directly addresses my question. The Powershell approach seems like the quickest way too. :) Unfortunately... I want to find the path of an EXE after running a separate DOS batch file that modifies the PATH environment variable. In Powershell, running the batch file requires a separate cmd.exe to be run, which means the PATH in Powershell is unaffected and so my target exe (tf.exe) still can't be located. Still, I should've said that in my question. Just didn't think it was important at the time. :-/
    – Mal Ross
    Sep 3, 2009 at 10:32
  • 1
    Using the taskmanager in Windows 7 (maybe Vista too), you can also right-click the process and choose "Open File Location". You don't need to install 3rd-party software like process explorer for this. If you know the processname, you can also type get-process processname | % { $_.path } to find the executable-path. However, this works not for every process. I haven't found the rule for that yet...
    – wullxz
    May 23, 2012 at 20:55
5

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

C:> which notepad
/c/WINDOWS/system32/notepad
3
  • nice. but try "which dir"...
    – nik
    Sep 3, 2009 at 9:27
  • +1, I do like the idea -- just that it needs a unix environment. You can also use the UnixUtil binary. unxutils.sourceforge.net
    – nik
    Sep 3, 2009 at 9:39
  • There are several which implementations floating around which run without the Unix subsystem
    – Xetius
    Sep 3, 2009 at 9:43
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
2
  • doesn't work...
    – Chazt3n
    Nov 16, 2015 at 13:21
  • @Chazt3n It sounds unfounded at the moment. Please, explain how do you use? Nov 17, 2015 at 4:01
2

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.

1
  • As a side note, the where tool isn't included by default for Windows XP or earlier. I believe Microsoft started including it with Vista or 7, but I don't have either one available to confirm.
    – Jesse
    Apr 3, 2015 at 20:55
0

You could try

CD \
dir /s command.*

or from explorer just do a search for the command name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .