0

I have a question regarding environment variables in Windows. So, I set an environment variable using SETX command:

SETX my_var VAR

After that, I use SET m to see if my variable is set. It shows it isn't. However, the variable appears in HKCU\Environment. I exit the command prompt window and open a new one. Typing SET m again makes my variable appear. I restart explorer.exe and open a new command prompt window. When using SET m, my variable isn't there anymore, but it is in HKCU\Environment.

I don't understand this behavior. Shouldn't it appear also after restarting explorer.exe, giving the fact that it is still in HKCU\Environment? I am missing something, I just don't understand what.

Later edit: I have tried doing the same thing on a computer running Windows 7 and I found out there is no problem. Don't know what is wrong in my case. I want anyway to thank everybody for their help.

pixie
  • 507
  • 9
  • 21

2 Answers2

0

Works for me on windows 8.1 What windows version are you on?

nire
  • 448
  • 2
  • 13
  • 8.1 pro for me too. I am seeing the exact same things you see. However, after restarting explorer i do see my_var when executing set m in a cmd box. You're pc/user account is not on some policy that resets the env variables? – nire Aug 20 '14 at 09:24
  • That I do not know [not my personal home computer]. But if it were, shouldn't the variable no longer appear in HKCU\Environment after restarting explorer.exe? I will investigate on your remark anyway. – pixie Aug 20 '14 at 09:30
0

setx sets the variable for future sessions, not any existing session (including this one).

No-one ever claimed that there was any logical reason for the 'not this one' quirk. It's eacy to overcome though - just add SETXX.BAT somewhere on your path

SETXX.BAT

SETX %1 %2
set "%1=%2"

and execute it as

call SETXX my_var VAR

(you may need to play around with quotes if you are attempting to set(x) a value containing spaces)

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Still not working. Restarting explorer.exe is the problem, although I cannot see why this is happening. – pixie Aug 20 '14 at 09:57