0

What is the correct way to create and set a new System variable via the command line in Windows 7?

I know that it's possible through the GUI by doing the following: Control Panel => System => Advanced System settings => Environment variables => Add new System variable

I have read about SetX and this seems like correct way to do it, but I still have some questions:

  • If I wanted to create an environment variable called TNS_ADMIN and set the value as the path to my tnsnames.ora file, would below be the entire command?

    SetX TNS_ADMIN \\domain.blah\directory\DBA\OraUpdates /m

  • Would this automatically get added to the PATH variable? Or would I need to update the PATH variable separately after adding the new System variable?

Tom O.
  • 5,730
  • 2
  • 21
  • 35
  • Type setx /? and it will tell you. – Hans Passant Oct 26 '17 at 15:59
  • Be careful about using setx.exe to update `PATH`. Do not use the current `%PATH%` value. Read the system value via `reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PATH`. Parse the value from the output; append to it; and set it back via `setx.exe /M PATH "%NEW_PATH%"`. Take care not to expand percent variables in the string. Of course, create a restore point before messing with the registry and experiment on a dummy variable. – Eryk Sun Oct 29 '17 at 06:48

0 Answers0