查找将从Windows命令行执行的程序的path

说我有一个程序X.EXE安装在系统上的文件夹c:\abcd\happy\ 。 该文件夹位于系统path中。 现在假设系统上还有另一个程序,也称为X.EXE,但安装在c:\windows\文件夹中。

是否有可能从命令行快速find,如果我inputX.EXE两个X.EXE将启动? (但无需在任务pipe理器中查找或查看stream程细节)。

也许某种内置的命令,或者某种可以做这样的事情的程序? :

 detect_program_path X.EXE 

使用where命令。 列表中的第一个结果是将要执行的结果。

 C:\>记事本
 C:\ WINDOWS \ SYSTEM32 \ NOTEPAD.EXE
 C:\ WINDOWS \ NOTEPAD.EXE

根据这个博客文章 ,Windows Server 2003及更高版本中包含了where.exe ,因此这应该只适用于Vista,Win 7等。

在Linux上,相当于which命令,例如which ssh

这里有一个你可以复制粘贴到一个名为where.cmd的文件的cmd脚本:

 @echo off rem - search for the given file in the directories specified by the path, and display the first match rem rem The main ideas for this script were taken from Raymond Chen's blog: rem rem http://blogs.msdn.com/b/oldnewthing/archive/2005/01/20/357225.asp rem rem rem - it'll be nice to at some point extend this so it won't stop on the first match. That'll rem help diagnose situations with a conflict of some sort. rem setlocal rem - search the current directory as well as those in the path set PATHLIST=.;%PATH% set EXTLIST=%PATHEXT% if not "%EXTLIST%" == "" goto :extlist_ok set EXTLIST=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH :extlist_ok rem - first look for the file as given (not adding extensions) for %%i in (%1) do if NOT "%%~$PATHLIST:i"=="" echo %%~$PATHLIST:i rem - now look for the file adding extensions from the EXTLIST for %%e in (%EXTLIST%) do @for %%i in (%1%%e) do if NOT "%%~$PATHLIST:i"=="" echo %%~$PATHLIST:i