Windows 7 Enviornment Variables will not stick through CMD or Power Shell (even if I run them as admin)

flip66

New Member
Joined
Oct 15, 2011
Messages
2
I have tried numerous times in both Command Prompt and Power Shell to set the Environment Variable for "Path" and it will not stick. I have tried running as admin as well.

If I test it in the open CMD or Powershell Window it seems to stick, but if I open a new window it is gone. If I go through System Properties and add it manually that way, it works just fine. Unfortunately I need it to work through a batch file or script.

I am running Windows 7 Pro 64-bit.

CMD code I have tried:
Code:
Set Path = C:\Program Files\Java\jdk1.7.0\bin;%Path%
Code:
Set Path = C:\Program Files\Java\jdk1.7.0\bin\;%Path%
Code:
Set Path = "C:\Program Files\Java\jdk1.7.0\bin";%Path%
Code:
Set Path = "C:\Program Files\Java\jdk1.7.0\bin\";%Path%

Power Shell code I have tried:
Code:
$Env:Path = $Env:Path + ";C:\Program Files\Java\jdk1.7.0\bin"
Code:
$Env:Path = $Env:Path + ";C:\Program Files\Java\jdk1.7.0\bin\"
 


Solution
Setting environment variables in Windows 7 via Command Prompt or PowerShell can sometimes be a bit tricky. Here are some insights and suggestions to help resolve the issue you are facing:

Command Prompt (CMD) Code:​

In CMD, when setting the Path environment variable, you should not use spaces around the = sign in your set command. Remove the spaces before and after the =. Also, it's recommended to use the setx command, which is used to set environment variables persistently. Here's the correct way to set the Path environment variable in Command Prompt:
Code:
setx Path "C:\Program Files\Java\jdk1.7.0\bin;%Path%"

PowerShell Code:​

Similarly in PowerShell, you can use the following to...
Setting environment variables in Windows 7 via Command Prompt or PowerShell can sometimes be a bit tricky. Here are some insights and suggestions to help resolve the issue you are facing:

Command Prompt (CMD) Code:​

In CMD, when setting the Path environment variable, you should not use spaces around the = sign in your set command. Remove the spaces before and after the =. Also, it's recommended to use the setx command, which is used to set environment variables persistently. Here's the correct way to set the Path environment variable in Command Prompt:
Code:
setx Path "C:\Program Files\Java\jdk1.7.0\bin;%Path%"

PowerShell Code:​

Similarly in PowerShell, you can use the following to append to the Path variable:
Code:
$env:Path = "$env:Path;C:\Program Files\Java\jdk1.7.0\bin"

Additional Tips:​

  1. Administrator Privileges: Ensure that you are running Command Prompt or PowerShell as an administrator. Right-click on the application and choose "Run as administrator" to make sure the changes have the necessary permissions.
  2. User vs. System Environment Variables: Depending on whether you need the variable for the current user or system-wide, you should set the variable accordingly. For system-wide changes, you may need administrative privileges.
  3. Check Environment Variables: After running the command successfully, you can check if the variable has been set correctly by typing echo %Path% in a new Command Prompt or PowerShell window.
  4. Batch Script: If you need to set this path using a batch script, be sure to run the batch script as administrator to make persistent changes to the system environment. Try these suggestions and see if they help in persistently setting the Path environment variable on your Windows 7 machine. Let me know if you encounter any issues or need further assistance!
 


Solution
Back
Top