407

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?

Zim
  • 107
David.Chu.ca
  • 5,535

14 Answers14

686

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.

ZygD
  • 2,577
Simon D
  • 7,061
52

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

stevec
  • 973
33

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!

geo
  • 673
18

open Powershell and use gcm command

gcm [your_exe]

demo

enter image description here

Source: Get-Command

Supplement

You can also use Select-Object alias: select to filter that field you are interested in.

for example:

gcm git.exe | select Source

enter image description here

Carson
  • 293
15

Note that some things might be a little different for PowerShell:

PS C:\Users\Rob.wb-devel> where ping

PS C:\Users\Rob.wb-devel> where git

PS C:\Users\Rob.wb-devel> whereis.bat git
C:\Program Files (x86)\Git\cmd\git.exe

PS C:\Users\Rob.wb-devel> where.exe git
C:\Program Files (x86)\Git\cmd\git.exe
Rob Jens
  • 251
  • 2
  • 3
13

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.

3

If you're using Powershell, where is something totally different than cmd's where.

In powershell, type:

(Get-Command powershell.exe).Path
Donal
  • 131
  • 4
3

Frustrating that it's not built-in as a simple command.

However, there are several solutions, one of which is a batch file.

Create a batch file (which.bat) as follows:

@setlocal
@set P2=.;%PATH%
@for %%e in (%PATHEXT%) do @for %%i in (%~n1%%e) do @if NOT "%%~$P2:i"=="" echo %%~$P2:i 

This looks in the local directory, will take a filename parameter with or without an extension, and return the first match from the current directory or in the PATH.

Then run it like which cmd.exe to find the cmd.exe that will execute if you type in cmd.

b w
  • 2,784
3

On windows you can use the free utility Everything search engine to search instantly for any file by full or partial name (if your hard disk is formatted in ntfs).

harrymc
  • 498,455
1

If you just want which, the GnuWin32 project has a bunch of unix utils with individual installers.

Justin Love
  • 1,006
1

In PowerShell

(@($env:path.split(";")) + (pwd).Path)  | where { dir $_ -ErrorAction SilentlyContinue |? Name -eq foo.exe }

You can easily convert this into a Cmdlet.

Another way to accomplish this, as suggested in an edit:

get-command notepad.exe | select Source
Anupam
  • 111
0

Heh, I just have to post this Windows' one liner batch file:

C:>type wh.cmd
@for %%f in (%*) do for %%e in (%PATHEXT% .dll .lnk) do for %%b in (%%f%%e) do for %%d in (%PATH%) do if exist %%d\%%b echo %%d\%%b

A test:

C:>wh ssh
C:\cygwin64\bin\ssh.EXE
C:\Windows\System32\OpenSSH\\ssh.EXE

Not quite a one-liner if you wrap the code in setlocal enableextensions and endlocal, which are required for users who don't have the extensions enabled by default.

bobbogo
  • 1,283
0

WHERE is great, but slow. I found querying registry to be faster, but less reliable so I combined the two ideas into a function like so:

app_path_func.cmd:

@ECHO OFF
CLS

FOR /F "skip=2 tokens=1,2* USEBACKQ" %%N IN (reg query &quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%~1&quot; /t REG_SZ /v &quot;Path&quot;) DO ( IF /I "%%N" == "Path" ( SET wherepath=%%P%~1 GoTo Found ) )

FOR /F "tokens=* USEBACKQ" %%F IN (where.exe %~1) DO ( SET wherepath=%%F GoTo Found )

FOR /F "tokens=* USEBACKQ" %%F IN (where.exe /R &quot;%PROGRAMFILES%&quot; %~1) DO ( SET wherepath=%%F GoTo Found )

FOR /F "tokens=* USEBACKQ" %%F IN (where.exe /R &quot;%PROGRAMFILES(x86)%&quot; %~1) DO ( SET wherepath=%%F GoTo Found )

FOR /F "tokens=* USEBACKQ" %%F IN (where.exe /R &quot;%WINDIR%&quot; %~1) DO ( SET wherepath=%%F GoTo Found )

:Found SET %2=%wherepath% :End

Test:

@ECHO OFF
CLS

CALL "app_path_func.cmd" WINWORD.EXE PROGPATH ECHO %PROGPATH%

PAUSE

Result:

C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE
Press any key to continue . . .

https://www.freesoftwareservers.com/display/FREES/Find+Executable+via+Batch+-+Microsoft+Office+Example+-+WINWORD+-+Find+Microsoft+Office+Path

-2

If you just need the path to launch it, it's often better to use the start command. For example, you can use "start chrome.exe" to start Chrom{e|ium}, regardless of where it is installed.