Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Windows equivalent of whereis?

I'm used to saying "which foo" on Unix systems to see what's going to run.

Today I'm having trouble with a program on Windows, and I think it may be the wrong command that's running. How do I determine, from cmd.exe, what program it's actually going to run when I type "foo"?

share|improve this question

marked as duplicate by akira, ChrisF, harrymc, random Jul 18 '10 at 0:31

This question was marked as an exact duplicate of an existing question.

akira: Great find! (I was having trouble getting SU to believe that I wanted to find the word "which".) Can I bless a comment into an answer? :-) – Ken Jul 16 '10 at 19:56

I would suggest, using your "foo" example, typing

foo /?

That should do similar on windows as adding --help does in linux. Not always, mind you, but it should let you know exactly what's going on, as well as some command syntax.

share|improve this answer
But running foo /? doesn't show which directory it is running from, only how to run it, which is not what the OP is asking. – steve.lippert Jul 16 '10 at 19:04
@steve.lippert .. true, but getting the usage back often indicates something about the program itself - though maybe not enough in all cases – warren Jul 16 '10 at 19:07
Unfortunately, in this case it's a command that has no visible output, or gives a generic error message. From /? (and any other flags I can think up) I can't tell exactly which one it's running. – Ken Jul 16 '10 at 19:08

I don't know of a 'which' for Windows, but from the command line you can run path to see where it is looking for the files. I believe it searches the path in order and will run the first executable it finds.

Remember that CMD.EXE will also search the local directory for a program to run and I believe this takes precedence.

share|improve this answer
I thought I've heard that cmd.exe has some special cases that aren't in %PATH%, which is why I'm asking. Plus I don't love the idea of hunting through all of the paths myself. :-) – Ken Jul 16 '10 at 19:09

To expand on steve's answer, from %SYSTEM_ROOT% you can run an attrib search to see where 'foo' lives, then compare to the %PATH% to see which would execute first:

attrib /s foo.exe
echo %PATH%
share|improve this answer
Good to know! But the variable is %systemroot%. cd %systemroot%, attrib /s ping.exe – steve.lippert Jul 16 '10 at 19:20
-1: attrib /s foo.exe just searches the current directory and all subdirectories for foo.exe. (You could do the same thing with dir /a-d /s /b foo.exe or Win+F.) On my computer, %SYSTEMROOT% is C:\WINDOWS, so you're really just searching in that directory and below. You could cd \ first, or use Win+F to search for foo.exe, but those preform really long searches, when you really just need to search the path. – Bavi_H Jul 17 '10 at 1:33

The which that comes with Cygwin ( will run from cmd.exe and probably do what you want otherwise. Be aware that if you're looking for a .bat, you need to explicitly add the .bat, e.g., "which gorp.bat" will find gorp.bat, but "which gorp" will not.

share|improve this answer
Nice idea, but unfortunately this is a server which doesn't have Cygwin, and I'm not sure they want me installing Cygwin there. – Ken Jul 16 '10 at 19:55

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