Hopefully "ScriptingTipsAndTricks" helps you with your batch file or vbscript scripting :-)
[Bottom][Contents][Prev]: Parameter Replacement[Next]: Redirection of STDIN, STDOUT & STDERR Input/Output Streams
\->Introduction->PATH Environment Variable (locations to search)

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.


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Parameter Replacement[Next]: Redirection of STDIN, STDOUT & STDERR Input/Output Streams


ScriptingTipsAndTricks© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday September 07 2014 at 12:50pm
Visit ScriptingTipsAndTricks's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.