How do I find the location of an executable in Windows?

I remembered that I used a tool called as where to find locations for any executable programs like this in a console:

 C:\Tmp\Where myTool.exe
 C:\Program Files\MyApp\myTools.exe
 ....

Now I cannot find this tool. Not sure if Windows has a build-in tool to do that search?


Solution 1:

According to the Stack Overflow answer at Is there an equivalent of 'which' on windows?, where.exe does this on Windows 7 and Windows Server 2003 and later:

Example

C:\> where ping

Output:

C:\Windows\System32\PING.EXE

In PowerShell use where.exe, Get-Command (or its abbreviation gcm), as where is the default alias for Where-Object.

Solution 2:

EDIT: I should have added, if you can't use the WHERE command from the command prompt, check your PATH variable. (Just use the "path" command.) Make sure C:\Windows\System32 is in your path. That's where "where.exe" is located.

WHERE is the command you're looking for! WHERE is like a cross between the UNIX shell built-in "which" and the "locate" command, in that it works for both command executables and regular files.

It's also somewhat more complex than either of those two, although, in general a simple

WHERE <file>

will work.

It's different from the "locate" command in that it's not looking through the entire filesystem. Instead, the default behavior is to look for files in two locations:

  • The current directory.
  • All of the directories in the PATH variable.

So, any command that you can run directly from a command prompt without specifying the directory, will be found by the WHERE command. (Because any command like that is already in the PATH variable list.)

If you want to search only in the command path variable, you can use:

WHERE "$path:<search text>"

If, on the other hand, you want to find all copies of a file in a directory tree, you can use:

WHERE /R <Top Level Directory> <search text>

Finally, WHERE will find commands and any files with an extension from the PATHEXT variable without including the extension. All other files have to be specified either exactly or with wildcards.

Take for example the files "dxdiag.exe" and "dxdiagn.dll". Note the following command and its output:

WHERE /R C:\Windows dxdiag

C:\Windows\System32\dxdiag.exe
C:\Windows\SysWOW64\dxdiag.exe
C:\Windows\WinSxS\amd64_microsoft-windows-d..x-directxdiagnostic_31bf3856ad364e35_6.2.9200.16384_none_7c8d3f96e7882ec7\dxdiag.exe
C:\Windows\WinSxS\x86_microsoft-windows-d..x-directxdiagnostic_31bf3856ad364e35_6.2.9200.16384_none_206ea4132f2abd91\dxdiag.exe

It succeeds in returning all versions of "dxdiag.exe" because ".exe" is one of the extensions in the PATHEXT variable. (Note: "WHERE dxdiag" would have worked as well, because C:\Windows\System32 is in the PATH variable.)

WHERE /R C:\Windows dxdiagn

on the other hand, fails to return any result, because ".dll" is not in PATHEXT.

In this case, look at the result that adding a wildcard gives us:

WHERE /R C:\Windows dxdiagn*

C:\Windows\System32\dxdiagn.dll
C:\Windows\System32\en-US\dxdiagn.dll.mui
C:\Windows\SysWOW64\dxdiagn.dll
C:\Windows\SysWOW64\en-US\dxdiagn.dll.mui
C:\Windows\WinSxS\amd64_microsoft-windows-d..iagnostic.resources_31bf3856ad364e35_6.2.9200.16384_en-us_daccd04369b09c70\dxdiagn.dll.mui
C:\Windows\WinSxS\amd64_microsoft-windows-d..x-directxdiagnostic_31bf3856ad364e35_6.2.9200.16384_none_7c8d3f96e7882ec7\dxdiagn.dll
C:\Windows\WinSxS\x86_microsoft-windows-d..iagnostic.resources_31bf3856ad364e35_6.2.9200.16384_en-us_7eae34bfb1532b3a\dxdiagn.dll.mui
C:\Windows\WinSxS\x86_microsoft-windows-d..x-directxdiagnostic_31bf3856ad364e35_6.2.9200.16384_none_206ea4132f2abd91\dxdiagn.dll

It successfully returns all versions of dxdiagn.dll.

For more information, use "WHERE /?". Hope this helps!

Solution 3:

For me, what worked was

Get-Command chromedriver

which returns something like

CommandType     Name                       Version    Source
-----------     ----                       -------    ------
Application     chromedriver.exe           0.0.0.0    C:\WINDOWS\chromedriver.exe

Simply replace chromedriver with the program you're looking for

Solution 4:

use dir:

cd \
dir /s /b mytool.exe

the cd \ part changes you to the root of the drive, to ensure searching starts at the top of the hierarchy.