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

  • 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. – user1686 May 29 '10 at 15:58
  • @grawity: Not even that, in places. For example the for statement has differing (and incampatible) behavior. – Joey May 30 '10 at 9:26
  • @Johannes: Depends on whether "command prompt extensions" is on, I think. – user1686 May 30 '10 at 11:13
  • @grawity: Not even then. – Joey May 30 '10 at 17:13

Use SETX as per answers in this thread (linked from the right hand side here as a related question): Is there a way to set Windows environment variables from the command line PERMANENTLY


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.


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.
  • 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

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

  • Is there a .bashrc or .bash_profile equivalent for DOS? – snmcdonald May 28 '10 at 20:49

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