Skip to main content
Fixes a typo, a couple of misspellings, and changed technet links to point to US English versions of the references.
Source Link
martineau
  • 4.5k
  • 24
  • 29

UPDATE NO.2 - Now to the actual question: Why don'tdo nested, user-created variables fail to expand?

There's some gerenalgeneral problems concerning variable expansion in Windows. I've already run into the same problem and found no clear, reproducablereproducible circumstances - the recursion level at which expansion fails is not consistent, special characters don't seem to play a role, etc.

The only viable workaround I found is adding variables recursion level by recursion level. That means: Try deleting all variables you want to nest into each other (including calls from PATH to your user-defined variables), and then start up from scratch. Define your basic variables (etc. ANT-HOME), commit, check if it's expanded, if it is, go on with the next level commit, check... you get the idea.

UPDATED ANSWER - Defining permanent environment variables using the CLI and GUI - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNetfull reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows ServerTechNet Command-line reference for Windows Server

UPDATE NO.2 - Now to the actual question: Why don't nested, user-created variables fail to expand?

There's some gerenal problems concerning variable expansion in Windows. I've already run into the same problem and found no clear, reproducable circumstances - the recursion level at which expansion fails is not consistent, special characters don't seem to play a role, etc.

The only viable workaround I found is adding variables recursion level by recursion level. That means: Try deleting all variables you want to nest into each other (including calls from PATH to your user-defined variables), and then start up from scratch. Define your basic variables (etc. ANT-HOME), commit, check if it's expanded, if it is, go on with the next level commit, check... you get the idea.

UPDATED ANSWER - Defining permanent environment variables using the CLI and GUI - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

UPDATE NO.2 - Now to the actual question: Why do nested, user-created variables fail to expand?

There's some general problems concerning variable expansion in Windows. I've already run into the same problem and found no clear, reproducible circumstances - the recursion level at which expansion fails is not consistent, special characters don't seem to play a role, etc.

The only viable workaround I found is adding variables recursion level by recursion level. That means: Try deleting all variables you want to nest into each other (including calls from PATH to your user-defined variables), and then start up from scratch. Define your basic variables (etc. ANT-HOME), commit, check if it's expanded, if it is, go on with the next level commit, check... you get the idea.

UPDATED ANSWER - Defining permanent environment variables using the CLI and GUI - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

Adapted answer to actual question ;)
Source Link
Tobias Plutat
  • 5.6k
  • 1
  • 25
  • 19

UPDATE NO.2 - Now to the actual question: Why don't nested, user-created variables fail to expand?

There's some gerenal problems concerning variable expansion in Windows. I've already run into the same problem and found no clear, reproducable circumstances - the recursion level at which expansion fails is not consistent, special characters don't seem to play a role, etc.

The only viable workaround I found is adding variables recursion level by recursion level. That means: Try deleting all variables you want to nest into each other (including calls from PATH to your user-defined variables), and then start up from scratch. Define your basic variables (etc. ANT-HOME), commit, check if it's expanded, if it is, go on with the next level commit, check... you get the idea.

UPDATED ANSWER - Defining permanent environment variables using the CLI and GUI - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

UPDATED ANSWER - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

UPDATE NO.2 - Now to the actual question: Why don't nested, user-created variables fail to expand?

There's some gerenal problems concerning variable expansion in Windows. I've already run into the same problem and found no clear, reproducable circumstances - the recursion level at which expansion fails is not consistent, special characters don't seem to play a role, etc.

The only viable workaround I found is adding variables recursion level by recursion level. That means: Try deleting all variables you want to nest into each other (including calls from PATH to your user-defined variables), and then start up from scratch. Define your basic variables (etc. ANT-HOME), commit, check if it's expanded, if it is, go on with the next level commit, check... you get the idea.

UPDATED ANSWER - Defining permanent environment variables using the CLI and GUI - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

added 307 characters in body; deleted 126 characters in body
Source Link
Tobias Plutat
  • 5.6k
  • 1
  • 25
  • 19

UPDATED ANSWER - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this is, hit the syntax:Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

So forTo add new values to path that's, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

UPDATED ANSWER - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, this is the syntax:

So for path that's

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

UPDATED ANSWER - Scroll down for the original answer

GUI method:

On Windows 7, just type "system" in the META-Prompt and you'll see an entry "Edit the System Environment Variables". From there, click "Environment variables". There, you can either edit the system variable PATH (bottom list) or add/edit a new PATH variable to the user environment variables.

Command line method:

To change environment variables permanently, you have to use the SETX command in the Windows command line. Unlike in other versions of Windows, it comes built-in with Windows 7. Its syntax differs a lot from SET, but it's also powerful. You'll have to be a bit careful though, it's easy to make a mess of your variables with SETX.

  • By default, you change user variables. You can have a PATH user environment variable that happily coexists with the system PATH variable. If you don't have it defined yet, do so by typing: SETX PATH yourpath

  • You can also add a value to the system variable PATH. To do this, you first need to bring up a command line with admin privileges. To do this, hit the Meta(Windows) key, type cmd and hit CTRL+ SHIFT+ENTER and confirm the UAC dialog.

To add new values to path, you can now enter

setx path "%path%;yournewpath" /m

It's important to follow that syntax! If you don't include %path% first, all existing values of path will be lost and replaced with only you new path. The /m switch at the end sets the variable in the system environment.

Please note that you'll have to bring up a new command line to make use of your new variable.

There's also a full reference for SETX at TechNet.

OLD ANSWER The command SET updates the variables only for the duration of the current command line session.

The correct syntax for adding a value to a variable is 'set [variable]=%[variable]%;[new value]`

Note that left of the equal sign, you have to omit the percent signs!

Source: TechNet Command-line reference for Windows Server

added 168 characters in body; added 126 characters in body
Source Link
Tobias Plutat
  • 5.6k
  • 1
  • 25
  • 19
Loading
Edited in SETX explanations; added 251 characters in body; deleted 2 characters in body; Post Made Community Wiki
Source Link
Tobias Plutat
  • 5.6k
  • 1
  • 25
  • 19
Loading
added 136 characters in body
Source Link
Tobias Plutat
  • 5.6k
  • 1
  • 25
  • 19
Loading
Source Link
Tobias Plutat
  • 5.6k
  • 1
  • 25
  • 19
Loading