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

Zab*_*bba 121 windows command-line path

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

是否有可能从命令行快速找出我是否输入X.EXE了两个中的哪一个X.EXE将被启动?(但无需在任务管理器中搜索或查看流程详细信息).

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

detect_program_path X.EXE
Run Code Online (Sandbox Code Playgroud)

Chr*_*ich 220

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

C:\> where notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe

根据这篇博客文章,where.exe它包含在Windows Server 2003及更高版本中,所以这应该适用于Vista,Win 7等.

在Linux上,等效于which命令,例如which ssh.

  • +1!我从来不知道这可能是Windows的一部分,因此没有朝这个方向看!:) (2认同)
  • @Kenny:你所要求的与这里发布的答案截然不同.您应该使用您已完成的研究创建一个新的Stack Overflow问题,并在这些评论中发布一个链接. (2认同)

Mic*_*urr 10

这是一个小cmd脚本,您可以将其复制粘贴到名为以下内​​容的文件中where.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
Run Code Online (Sandbox Code Playgroud)


Eug*_*ene 7

正如评论中提到的线程get-command在powershell中也可以解决。例如,您可以键入get-command npm,输出如下:

在此处输入图片说明