307

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?

3

14 Answers 14

552

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.

9
  • 25
    This should be makred as the correct answer as it works without installing extra software
    – Cookie
    Oct 17, 2014 at 12:28
  • 52
    An important part of this answer is that in powershell, where is a default alias for the Where-Object, so you instead need to use where.exe, or gcm/Get-Command Nov 13, 2017 at 18:03
  • 2
    What about powershell. How can I achieve the same in powershell?
    – krv
    Sep 15, 2018 at 14:12
  • 6
    @krv As @DaveAndersen mentioned, in powershell you can type Get-Command ping (or just gcm ping), which will give you full path, along with some other info.
    – Sam
    Jan 9, 2019 at 9:25
  • 3
    @stevec please read the above comment: in PowerShell you must use where.exe instead of where
    – phuclv
    Mar 30, 2020 at 2:11
28

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!

2
  • 3
    where where C:\Windows\System32\where.exe :)
    – vp_arth
    Dec 6, 2016 at 15:13
  • 1
    @vp_arth Was just thinking exactly the same thing :) May 31, 2019 at 13:54
19

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

14

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
3
  • Thanks, this works for both cmd and PowerShell Jan 17, 2019 at 12:12
  • 1
    "whereis" whereis.bat ???;)
    – Timo
    Mar 20, 2020 at 13:51
  • For Powershell as an addition please see my comment on @john t answer.
    – Timo
    Mar 20, 2020 at 13:52
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.

7
  • It seems like doing a command line Windows Search.
    – Ganesh R.
    Sep 30, 2009 at 17:18
  • 8
    That does a recursive search of the drive and would take forever.
    – djhowell
    Sep 30, 2009 at 17:19
  • 9
    The only way to find executables that AREN'T in the PATH environment variable is to do this. He never specified his path, he said any executable.
    – John T
    Sep 30, 2009 at 17:31
  • it does find the executable but takes a while.
    – Michael Z
    Sep 2, 2012 at 22:43
  • 1
    this of course only works if you know the name of the executable or at least a portion of the name Nov 17, 2016 at 9:04
12

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

2
  • Works great, thanks! Mar 2, 2021 at 11:54
  • Can't believe I had to scroll so low to finally find a working command. The only one that can tell me where is gdb located. Thanks May 15 at 9:15
4

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).

1
  • 1
    Night and day difference between this and windows search.
    – AnthonyVO
    Dec 15, 2016 at 15:42
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.

3

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

In powershell, type:

(Get-Command powershell.exe).Path
1
  • Cheers. Didn't notice the typo.
    – Donal
    Apr 29, 2020 at 13:24
1

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

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
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.

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 "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\%~1" /t REG_SZ  /v "Path"`) 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 "%PROGRAMFILES%" %~1`) DO (
 SET wherepath=%%F
 GoTo Found
)

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

FOR /F "tokens=* USEBACKQ" %%F IN (`where.exe /R "%WINDIR%" %~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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.