In Windows 7, is it possible to set a path that automatically applies to every new Command Prompt (DOS) instance, but nowhere else? Note that the Advanced tab for My Computer properties as well as the DOS SETX command fail to address that last constraint.
1 Answer
The command prompt in Windows supports an AutoRun registry key that allows you to run a program each time a command prompt is opened.
Set
sets variables, but only for that command session (whereas Setx
is persistent), so that'll be what you want to use.
Example usage:
- Head to
%USERPROFILE%
(usuallyC:\users\<user name>
). - Create a new batch file with your commands in it.
e.g. (append a path to the existing PATH variable):
@echo off
set path=%path%;"C:\Extra Path To Include"
- Save the file (for example
test.bat
). - Open RegEdit and head to "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor".
- Add a new Value named "AutoRun" with a Type of "REG_EXPAND_SZ" (Expandable String Value).
- Double-click the new value to edit the data.
- Add
%USERPROFILE%\test.bat
as the Value data.
OK everything and close RegEdit.
Open a command prompt (no reboot necessary) and your batch file should have run, setting the Path (which you can confirm with set path
).