开发者

How to check from what path application is run?

For example I have entered

netsh.exe

in command line (aka cmd.exe)

Now I would like to know which netsh.exe is being run, lets say I have more than one netsh.exe on my PATH (I do know that the first one in the PATH will be run, but lets say I have a very BIG PATH and I don't have time to search for it man开发者_运维问答ually. To be fair its not always your machine you are using and many times PATH is set by admins and many times they are not the best).

Is there any way in windows to find that out from command line? I want to write a BATCH application that is using that.


It's a one-liner batch file:

@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

Save this as whereis.cmd, then type

whereis netsh


I think the following blog post does exactly what you want: http://pankaj-k.net/weblog/2004/11/equivalent_of_which_in_windows.html


I would use Windows Management Instrument (WMI) to query:

"SELECT ExecutablePath FROM Win32_Process WHERE Name = 'netsh.exe'"

http://www.activexperts.com/activmonitor/windowsmanagement/wmi/samples/ WMI samples

You will need to find something suitable for your scripting


On Windows Server (at least 2003 and 2008, dont know with 2000) you can use where.exe

Where.exe /?
Description:
Displays the location of files that match the search pattern.
By default, the search is done along the current directory and
in the paths specified by the PATH environment variable.
...

The first file listed is also the first file windows will use.
I use a copy on my XP workstation and it works fine too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜