Determining which PATH component is used to find a binary in XP

B

bagarow

Hi

How do I determine which component of the PATH environment variable was
the first file path that had the binary being executed...

e.g. if there is java.exe in C:\Windows\system 32 and in C:\Program
Files\Java\jdk1.5.0_02\bin and the PATH variable contains
C:\Windows\system32 before
c:\Program Files\Java\jdk1.5.0_02, then I know if I execute java.exe it
comes from C:\Windows\system32.

Is there a utility that will automatically determine the source of the
executable? I suppose I could write one that would search each
component of the PATH variable in order. But if there is an existing
utility i would like to use that instead.

Thanks
Bob
 
D

Doug Knox MS-MVP

The PATH is parsed in order of the entries, so Windows\System32 will be checked first.
 
J

Jon

Hi

How do I determine which component of the PATH environment variable was
the first file path that had the binary being executed...

e.g. if there is java.exe in C:\Windows\system 32 and in C:\Program
Files\Java\jdk1.5.0_02\bin and the PATH variable contains
C:\Windows\system32 before
c:\Program Files\Java\jdk1.5.0_02, then I know if I execute java.exe it
comes from C:\Windows\system32.

Is there a utility that will automatically determine the source of the
executable? I suppose I could write one that would search each
component of the PATH variable in order. But if there is an existing
utility i would like to use that instead.

Thanks
Bob

Try filemon
http://www.sysinternals.com/Utilities/Filemon.html

Jon
 
T

Tim Slattery

How do I determine which component of the PATH environment variable was
the first file path that had the binary being executed...

There's a "where.exe" utililty that's lived on our LAN for ever and
ever that does exactly this. Searching for it on Google turned up
this:

http://www.paulsadowski.com/WSH/cmdprogs.htm

It includes several command-line utilities, "which" is among them.
 
D

David Candy

A one line bat file (folder only)
echo %~dp$PATH:1
or (full path to file)
echo %~$PATH:1


Batfile.bat programfile

eg
SearchPath.bat notepad.exe

Understand that this only applies to the command prompt. The GUI uses
1.. The directory from which the application loaded.
2.. The current directory for the parent process.
3.. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

Windows Me/98/95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.


4.. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
5.. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6.. The directories that are listed in the PATH environment variable.
Also both will try all possibilities if you don't quote spaces.
The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space-delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:

c:\program.exe files\sub dir\program name
c:\program files\sub.exe dir\program name
c:\program files\sub dir\program.exe name
c:\program files\sub dir\program name.exe
 
D

David Candy

@echo off
set a=%~$PATH:1
If "%a%"=="" (Echo %1 not found) else (echo %a%)

Is a more polished version for the bat file.

--
--------------------------------------------------------------------------------------------------
How to lose a war in Iraq
http://webdiary.com.au/cms/?q=node/1335#comment-48641
=================================================
"David Candy" <.> wrote in message A one line bat file (folder only)
echo %~dp$PATH:1
or (full path to file)
echo %~$PATH:1


Batfile.bat programfile

eg
SearchPath.bat notepad.exe

Understand that this only applies to the command prompt. The GUI uses
1.. The directory from which the application loaded.
2.. The current directory for the parent process.
3.. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

Windows Me/98/95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.


4.. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
5.. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6.. The directories that are listed in the PATH environment variable.
Also both will try all possibilities if you don't quote spaces.
The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space-delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:

c:\program.exe files\sub dir\program name
c:\program files\sub.exe dir\program name
c:\program files\sub dir\program.exe name
c:\program files\sub dir\program name.exe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top