Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicates:
Set Permanent Environmental Variable in Windows XP
Is there a way to set Windows environment variables from the command line PERMANENTLY

The set command does not save values between cmd.exe sessions. How can I save environmental values between new cmd.exe sessions?

For example the set command will work for my current session only:

set path=%path%;C:\Mingw\bin

Upon restarting cmd.exe my path string has been reset.

Possible solution: .bashrc or .bash_profile equivalent for DOS

share|improve this question

marked as duplicate by akira, quack quixote May 29 '10 at 22:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
FYI, cmd.exe is not DOS. It is a native 32-bit Windows program. The only thing in common with MS-DOS is the command syntax. –  grawity May 29 '10 at 15:58
    
@grawity: Not even that, in places. For example the for statement has differing (and incampatible) behavior. –  Јοеу May 30 '10 at 9:26
    
@Johannes: Depends on whether "command prompt extensions" is on, I think. –  grawity May 30 '10 at 11:13
    
@grawity: Not even then. –  Јοеу May 30 '10 at 17:13
add comment

4 Answers

up vote 8 down vote accepted

Use SETX as per answers in this thread (linked from the right hand side here as a related question): http://superuser.com/questions/119838/is-there-a-way-to-set-windows-environment-variables-from-the-command-line-permane

share|improve this answer
1  
+1 SETX is the right answer here. –  MDMarra May 28 '10 at 21:33
add comment

Add/change them from Global environment variables. To access this (Assuming Windows XP as your OS ), right click on My Computer -> Properties -> Advanced Tab -> Environment Variables and add whatever is required.

share|improve this answer
add comment

You have several options:

Assuming Windows XP Pro:

  1. Go into c:\windows\system32\autoexec.nt and change to add the path there.
  2. Right click My Computer, go into properties, Advanced, Environmental Variables, change there.
  3. Create a login script. Right click My Computer, go into Manage. Go into Local Users and Groups, then Users. Right click the login, choose properties, go into Profile and set th Logon script. The default location it looks for login scripts are c:\windows\system32\repl\import\scripts.
share|improve this answer
    
What is a login script going to do? Using set only applies to that specific cmd instance. It will run and then not affect any following command prompt sessions. –  MDMarra May 28 '10 at 21:34
    
You can set the environment in the login. It then that gets forced into the environment variable space. Subsequent command prompt sessions inherit those variables. SetX or Setenv can be used here. –  Blackbeagle May 28 '10 at 22:18
    
You don't need to use setx or setenv more than once, so doing it every login is unnecessary. –  MDMarra May 28 '10 at 22:46
    
True, it should modify the registry. I isn't necessary to keep pushing it, but at least there is a stake marker somewhere that you did push something. If you did it from the command line or from the GUI, you don't know that it happened later. Keeping it here is redundant on boot, but a permanent place to look later to see what you did. –  Blackbeagle May 29 '10 at 0:18
    
echo %path% should be enough to show you what you've added to your path. –  MDMarra May 29 '10 at 5:00
add comment

To get Windows to save environment variables, Right-click on My Computer, click Properties, then Advanced | Environment Variables and edit it there.

share|improve this answer
    
Is there a .bashrc or .bash_profile equivalent for DOS? –  snmcdonald May 28 '10 at 20:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.