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

174

43

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?

David.Chu.ca

Posted 2009-09-30T17:06:38.947

Reputation: 2 967

4PAGING OP: Please update accepted answer :) – Jake – 2016-09-19T03:01:03.120

1@David.Chu.ca please update accepted answer – Matt Frear – 2018-08-10T09:09:19.390

It seems that OP does not log into this site anymore. The correct answer should be https://superuser.com/a/440904/736190

– jdhao – 2019-05-11T06:33:41.417

IF the application is running & you need to know its location, use Process Explorer( from Sys Internals). – Ganesh R. – 2009-09-30T17:19:51.617

2

Various answers over on Is there an equivalent of 'which' on windows? - Stack Overflow

– Satanicpuppy – 2009-09-30T17:17:55.007

6where worked for me on Windows 7 Enterprise – Bohemian – 2014-05-29T03:09:00.950

Answers

380

According to the StackOverflow 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.

Simon D

Posted 2009-09-30T17:06:38.947

Reputation: 3 973

20This should be makred as the correct answer as it works without installing extra software – Cookie – 2014-10-17T12:28:03.930

30An 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 – 2017-11-13T18:03:32.290

2What about powershell. How can I achieve the same in powershell? – krv – 2018-09-15T14:12:31.600

4@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 – 2019-01-09T09:25:32.957

@Sam for some reason the answer didn't work but yours did. – stevec – 2020-01-19T15:35:29.950

I have included information from @DaveAndersen in the answer - thanks. – Simon D – 2020-01-21T20:06:50.703

23

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

Posted 2009-09-30T17:06:38.947

Reputation: 557

2where where C:\Windows\System32\where.exe :) – vp_arth – 2016-12-06T15:13:51.223

1@vp_arth Was just thinking exactly the same thing :) – Reversed Engineer – 2019-05-31T13:54:46.250

10

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

Posted 2009-09-30T17:06:38.947

Reputation: 149 037

1this of course only works if you know the name of the executable or at least a portion of the name – Oliver Williams – 2016-11-17T09:04:27.087

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 – 2019-10-05T11:32:14.893

It seems like doing a command line Windows Search. – Ganesh R. – 2009-09-30T17:18:58.890

6That does a recursive search of the drive and would take forever. – djhowell – 2009-09-30T17:19:06.737

8The 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 – 2009-09-30T17:31:33.560

it does find the executable but takes a while. – Michael Z – 2012-09-02T22:43:59.873

9

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

Posted 2009-09-30T17:06:38.947

Reputation: 191

Thanks, this works for both cmd and PowerShell – Ding-Yi Chen – 2019-01-17T12:12:03.903

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

Posted 2009-09-30T17:06:38.947

Reputation: 2 424

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

Posted 2009-09-30T17:06:38.947

Reputation: 306 093

1Night and day difference between this and windows search. – AnthonyVO – 2016-12-15T15:42:25.357

1

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

Justin Love

Posted 2009-09-30T17:06:38.947

Reputation: 966

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

Posted 2009-09-30T17:06:38.947

Reputation: 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

Posted 2009-09-30T17:06:38.947

Reputation: 1 002

0

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

In powershell, type:

(Get-Command -powershell.exe).Path

Donal Mee

Posted 2009-09-30T17:06:38.947

Reputation: 101

0

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

Posted 2009-09-30T17:06:38.947

Reputation: 113

0

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.

Anonymous Coward

Posted 2009-09-30T17:06:38.947

Reputation: 1