356

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
  • 5
David.Chu.ca
  • 4,975
  • 9
  • 32
  • 36
  • IF the application is running & you need to know its location, use Process Explorer( from Sys Internals). – Ganesh R. Sep 30 '09 at 17:19
  • 2
    Various answers over on [Is there an equivalent of 'which' on windows? - Stack Overflow](http://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-windows) – Satanicpuppy Sep 30 '09 at 17:17
  • 7
    `where` worked for me on Windows 7 Enterprise – Bohemian May 29 '14 at 03:09

14 Answers14

622

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,459
  • 12
  • 26
  • 43
Simon D
  • 6,421
  • 2
  • 16
  • 14
  • 29
    This should be makred as the correct answer as it works without installing extra software – Cookie Oct 17 '14 at 12:28
  • 62
    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` – Dave Andersen Nov 13 '17 at 18:03
  • 2
    What about powershell. How can I achieve the same in powershell? – krv Sep 15 '18 at 14:12
  • 7
    @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 09 '19 at 09:25
  • @Sam for some reason the answer didn't work but yours did. – stevec Jan 19 '20 at 15:35
  • I have included information from @DaveAndersen in the answer - thanks. – Simon D Jan 21 '20 at 20:06
  • 3
    @stevec please read the above comment: in PowerShell you must use `where.exe` instead of `where` – phuclv Mar 30 '20 at 02:11
  • Sometimes this solution is not working. I have a strange annoying example: https://pasteboard.co/Jp1GQjr.png – recolic Sep 01 '20 at 06:38
  • Thanks, I was typing `where` on visual studio's shell and getting empty response whereas `where.exe` did the job. I didn't know about the alias to `where-object`! – Jack Nov 22 '20 at 15:33
32

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
  • 665
  • 6
  • 8
30

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
  • 641
  • 7
  • 16
16

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
  • 261
  • 2
  • 3
15

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
  • 253
  • 2
  • 7
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.

John T
  • 163,373
  • 27
  • 341
  • 348
  • It seems like doing a command line Windows Search. – Ganesh R. Sep 30 '09 at 17:18
  • 8
    That does a recursive search of the drive and would take forever. – djhowell Sep 30 '09 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 '09 at 17:31
  • it does find the executable but takes a while. – Michael Z Sep 02 '12 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 – Oliver Williams Nov 17 '16 at 09:04
  • Also, there are a few protected directories that will not be searched, containing the executable. This does not preclude to be a good alternative. – fcm Oct 05 '19 at 11:32
  • An example to use on the commandline: `cmd /c "dir /s /b pdfxedit.exe"`. `/b` is: Uses bare format (no heading information or summary, only the information itself). `/s` is recursive search. – Timo Mar 20 '20 at 13:17
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).

harrymc
  • 455,459
  • 31
  • 526
  • 924
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,684
  • 4
  • 28
  • 33
1

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

Justin Love
  • 1,006
  • 2
  • 23
  • 35
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
  • 3
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,253
  • 10
  • 11
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

FreeSoftwareServers
  • 1,317
  • 5
  • 23
  • 46
-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.