How does CMD.EXE find certain apps?

M

Michael Moser

I have an question re. application paths: how does the command-line
interpreter locate certain executables?

E.g.: I can enter "java -jar <someJarFile>" on the cmd-line and that
happily executes "C:\Program Files\Java\jre1.5.0_07\bin\java.exe". But
where does cmd know, where that java.exe sits? "C:\Program
Files\Java\jre1.5.0_07\bin" is NOT part of the PATH, there is no
environment variable relating to Java (like JAVA_HOME or JDK_HOME or
such defined), so where exactly does cmd get that info from?

Michael
 
J

JCO

It goes back to the old DOS days.
Your computer, durring boot, reads a path that has been predetermined.
Example is the Windows folder or the System and System32 folders. To see
your existing path, type Path in a DOS prompt (the CMD.exe) now known as the
Command Prompt. Your path will be displayed. Anything in the path, can be
executed from any folder, therefore, what you type in the Command Prompt is
searched in the existing Path automatically. When some programs get
installed, the install program may change your existing path by adding a
path to the new folder that was created for the installed programs.

If you want to add a specific folder to your path, you can do so too. This
is handy for Programmers (my self) because we can create executables and
have them execute with in a specific folder.

If you need to do that, let me know.
 
W

Wesley Vogel

happily executes "C:\Program Files\Java\jre1.5.0_07\bin\java.exe". But
where does cmd know, where that java.exe sits?
so where exactly does cmd get that info from?

java.exe, which I do not have, probably has a listing in the registry in App
Paths.

The Path environmental variable and a registry entry, App Paths,
control what paths do not have to be typed.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\
CurrentVersion\App Paths\java.exe
Value Name: Path
Data Type: REG_EXPAND_SZ
Value Data: Path to java.exe

Windows uses this key to find your application and its DLLs if their
locations are not already in the system's path.

This is also used for the command prompt, the Run command and others.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
A

Ayush

[Wesley Vogel]s message :
java.exe, which I do not have, probably has a listing in the registry in
App Paths.
Windows uses this key to find your application and its DLLs if their
locations are not already in the system's path.
This is also used for the command prompt, the Run command and others.

Are you sure ? command prompt only reads the path variable and current directory, afaik.


Good Luck, Ayush.
 
W

Wesley Vogel

Are you sure ? command prompt only reads the path variable and current
directory, afaik.

Let's try an example with a file that every Windows XP machine should have.

Open a command prompt, type: start msconfig and hit Enter.

Does msconfig.exe open? It does for me.

So how does cmd.exe know where msconfig.exe is?

msconfig.exe is in C:\WINDOWS\pchealth\helpctr\binaries

C:\WINDOWS\pchealth\helpctr\binaries is not in the path.

---------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>start msconfig

C:\>path
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program
Files\Intel\DMIX

C:\>
---------------------

This is how.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\
App Paths\MSCONFIG.EXE
Value Name: (Default)
Data Type: REG_SZ
Value Data: C:\WINDOWS\PCHealth\HelpCtr\Binaries\MSConfig.exe

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
Ayush said:
[Wesley Vogel]s message :
java.exe, which I do not have, probably has a listing in the registry in
App Paths.
Windows uses this key to find your application and its DLLs if their
locations are not already in the system's path.
This is also used for the command prompt, the Run command and others.

Are you sure ? command prompt only reads the path variable and current
directory, afaik.

Good Luck, Ayush.
 
A

Ayush

[Wesley Vogel]s message :
Let's try an example with a file that every Windows XP machine should have.

Open a command prompt, type: start msconfig and hit Enter.

Does msconfig.exe open? It does for me.


But not here. It just says
'msconfig' is not recognized as an internal or external command, ....


msconfig works from Run dialog.

Good Luck, Ayush.
 
W

Wesley Vogel

But not here. It just says
'msconfig' is not recognized as an internal or external command, ....

I think that you made an error. The command was...

start msconfig

Not...

msconfig

Start searches app paths.

All of the following start commands work for me from the command prompt.
None of the files are in the path. And all of the files are XP files, no
3rd party files involved. All of the files are listed in App Paths.

start HelpCtr

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\HELPCTR.EXE

start iexplore

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\IEXPLORE.EXE

start moviemk

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\moviemk.exe

start mplayer2

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\mplayer2.exe

start msimn

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\msimn.exe

start MSInfo32

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\msinfo32.exe

start wab

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\wab.exe

start wmplayer

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\wmplayer.exe

start WORDPAD

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\WORDPAD.EXE

start write (opens Wordpad.exe, similar to regedt32 starting regedit.exe)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\WRITE.EXE

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
Ayush said:
[Wesley Vogel]s message :
Let's try an example with a file that every Windows XP machine should
have. Open a command prompt, type: start msconfig and hit Enter.

Does msconfig.exe open? It does for me.


But not here. It just says
'msconfig' is not recognized as an internal or external command, ....


msconfig works from Run dialog.

Good Luck, Ayush.
 
A

Ayush

[Wesley Vogel]s message :
I think that you made an error. The command was...

start msconfig
Not...
msconfig
Start searches app paths.

With start, it works fine but I thought you are saying that command prompt(not start)
searches app paths key.
 
R

Ramesh, MS-MVP

Michael,

Are you sure that "jre1.5.0_07" is not added to the Path?
Hope you verified by typing PATH in Command Prompt.

If it's not there really, then see if a copy of "java.exe" is present in one of these locations:

%userprofile%
%windir%
%windir%\system32

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows Shell/User]
Windows® Troubleshooting http://www.winhelponline.com


I have an question re. application paths: how does the command-line
interpreter locate certain executables?

E.g.: I can enter "java -jar <someJarFile>" on the cmd-line and that
happily executes "C:\Program Files\Java\jre1.5.0_07\bin\java.exe". But
where does cmd know, where that java.exe sits? "C:\Program
Files\Java\jre1.5.0_07\bin" is NOT part of the PATH, there is no
environment variable relating to Java (like JAVA_HOME or JDK_HOME or
such defined), so where exactly does cmd get that info from?

Michael
 
W

Wesley Vogel

That's what I stated at first, and that's what I originally thought, but
then I drifted off into left field. And I was wrong.

So how *does* the java -jar <someJarFile> command work with java.exe located
in C:\Program Files\Java\jre1.5.0_07\bin and that not being in the path?

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
Ayush said:
[Wesley Vogel]s message :
I think that you made an error. The command was...

start msconfig
Not...
msconfig
Start searches app paths.

With start, it works fine but I thought you are saying that command
prompt(not start) searches app paths key.
 
A

Ayush

[Wesley Vogel]s message :
So how *does* the java -jar <someJarFile> command work with java.exe
located in C:\Program Files\Java\jre1.5.0_07\bin and that not being in
the path?

Because there is java.exe in system32 folder.


Good Luck, Ayush.
 
W

Wesley Vogel

Because there is java.exe in system32 folder.

Well, that certainly makes sense. Since I do not have java, I was unable to
check that, but it makes me feel like saying, Duh.

Thank you, Ayush.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
Ayush said:
[Wesley Vogel]s message :
So how *does* the java -jar <someJarFile> command work with java.exe
located in C:\Program Files\Java\jre1.5.0_07\bin and that not being in
the path?

Because there is java.exe in system32 folder.


Good Luck, Ayush.
 
W

Wesley Vogel

Hi Ramesh,

Even though your post is dated 2 April, I just now saw it. Hmm.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
Ramesh said:
Michael,

Are you sure that "jre1.5.0_07" is not added to the Path?
Hope you verified by typing PATH in Command Prompt.

If it's not there really, then see if a copy of "java.exe" is present in
one of these locations:

%userprofile%
%windir%
%windir%\system32

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows Shell/User]
Windows® Troubleshooting http://www.winhelponline.com


message I have an question re. application paths: how does the command-line
interpreter locate certain executables?

E.g.: I can enter "java -jar <someJarFile>" on the cmd-line and that
happily executes "C:\Program Files\Java\jre1.5.0_07\bin\java.exe". But
where does cmd know, where that java.exe sits? "C:\Program
Files\Java\jre1.5.0_07\bin" is NOT part of the PATH, there is no
environment variable relating to Java (like JAVA_HOME or JDK_HOME or
such defined), so where exactly does cmd get that info from?

Michael
 
M

Michael Moser

Bingo! Thanks for that description! I had already been puzzled quite a
while re. this capability, but recently cmd always picked up the wrong
version and that's why I really had to find out this time.

Thanks and cheers,
Michael
 
A

Admiral Q

Michael Moser said:
I have an question re. application paths: how does the command-line
interpreter locate certain executables?

E.g.: I can enter "java -jar <someJarFile>" on the cmd-line and that
happily executes "C:\Program Files\Java\jre1.5.0_07\bin\java.exe". But
where does cmd know, where that java.exe sits? "C:\Program
Files\Java\jre1.5.0_07\bin" is NOT part of the PATH, there is no
environment variable relating to Java (like JAVA_HOME or JDK_HOME or such
defined), so where exactly does cmd get that info from?

Michael

From the "cmd" line, type in "which java" and it should tell you exactly
where windows found the executable for "java". This should work for any
program you can run from the "cmd" line, then check your "PATH" variable to
see if that path is there.
 
W

Wesley Vogel

The Which Command looks handy. Too bad that it's a Linux and Unix command.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 

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