|
PATH Environment Variable (locations to search) |
A program you want to run does not need to be in the current directory for it to be found and executed, you could supply an absolute filename such as "C:\TOOLS\MyCommand.exe" in which case you are telling Windows exactly where the executable file is.
If you supply a relative filename such as "MyCommand.exe" then if it doesn't exist in the current directory Windows will search for it. It searches in a list of places Windows (and you) have specified. The following shows the command not being found:
C:\TMP> MyCommand.exe 'MyCommand.exe' is not recognized as an internal or external command, operable program or batch file. C:\TMP>
Windows will only search for files if the context is a command and the file extension is defined in the "PATHEXT" environment variable, the directories to be searched are stored in the "PATH" environment variable, the following shows how both these values can be displayed (I have trimmed the "PATH" as its very long):
C:\TMP> SET PATH Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Tools;C:\Tools\SysInternals;C:\Program Files (x86)\MakeMsi\ PATHEXT=.REX;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.4mm;.PY
If I typed the command "MyCommand" then the semi-colon delimitered paths are searched in order and since I didn't supply an extension it will look for "MyCommand.REX", "MyCommand.COM" etc in each of those an execute the first one found.
I like to always supply file extensions so I can be very sure what I'm about to execute.
![]() ![]() |
| ![]() ![]() |