PATH – Windows CMD Command

Display or set a search path for executable files at the command line.

PATH without parameters will display the current path.

The %PATH% environment variable contains a list of folders. When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan %PATH% to find it.

Use the PATH command to display or change the list of folders stored in the %PATH% environment variable.

It is important that the pathnames are delimited with semicolons NOT by quotes.
PowerShell in particular will ignore any path node delimited by double quotes.

Note you do not need to surround each part of the path with double quotes, PATH will automatically treat spaces as part of the filename.

Permanent Changes

Changes made using the PATH command are NOT permanent, they apply to the current CMD prompt only and remain only until the CMD window is closed.

To permanently change the PATH use

Control Panel, System, Environment, System Variables
Control Panel, System, Environment, User Variables

The %PATH% variable is set as both a system and user variable, the 2 values are combined to give the PATH for the currently logged in user. This is explained in full by MS Product Support Article Q100843

Be wary of using commands like SETX to modify the PATH – the User path can be edited, but the System path remains read-only for most users. If you try to delete an old value and add a new one it is very common for the ‘delete’ to fail and the ‘add’ to succeed, resulting in duplicate values being added to the path.

You can now easily change that one variable %MYAPP% at any time in the future and the PATH will reflect the new value.

  • Changing a variable in the Control Panel will not affect any CMD prompt that is already open, only new CMD prompts will get the new setting.
  • To change a system variable you must have administrator rights
  • If your system has an AUTOEXEC.BAT file then any PATH setting in AUTOEXEC.BAT will also be appended to the %PATH% environment variable. This is to provide compatibility with old installation routines that need to set the PATH. All other commands in AUTOEXEC.BAT are ignored.

PathExt

If you start/run an application without a file extension (for example WinWord instead of WinWord.exe)then the PATHEXT environment variable will be read to determine which file extensions to search for and in what order.
The default value for the PATHEXT variable is .COM;.EXE;.BAT;.CMD
Many would argue that.CMD should have a higher priority than legacy.BAT.

Dpath

DPATH is an undocumented internal utility that allows the TYPE command to read data files in specified directories as if they were in the current directory. On some OS’s this is also implemented as the now deprecated APPEND command. The list of directories is held in the %DPATH% environment variable which works just like the %PATH% variable, delimited with semicolons (no quotes). Syntax: DPATH pathname [;pathname]…

If a file reference uses only the filename rather than a full pathname, then that will work only if the file is in the current directory or is listed in the PATH.

Paths for GUI Windows applications

Since Windows 95, the App Paths registry subkey is available to provide a location for specific executable filenames. Populating this avoids the need for applications to modify the system PATH environment variable.

The keys can be found in the following two registry locations and full documentation of this is on docs.microsoft.com

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths

The filename used in App Paths does not have to match the destination file.

Errorlevels

When CMD Command Extensions are enabled (the default):

If the Path was successfully changed %ERRORLEVEL% = unchanged, typically this will be 0 but if a previous command set an errorlevel, that will be preserved (this is a bug).

If Path could not be changed %ERRORLEVEL% = 1

PATH is an internal command

You may also like...

Leave a Reply

Your email address will not be published.