Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am setting a environment variable with setx(win7) in a cmd , that I started from a batch file, if I close the shell an open a new from batch file again and use Set command to check it, I do not get this new variable. I can see the variable via windows and regedit, had someone an Idea what I do wrong?

EG.

Batch:

Rem set some local variables

Set varableA="test"

...

Start /B cmd.exe /k

In the opened shell:

Setx -m variableB value --> set system envirtomet vartiable

Close shell an run batch again

In the new shell:

Set var

And thgerre is not variableB but in Windows an registry I can see it

share|improve this question
    
-1 you should paste the command you used so people can repeat what you did. That's the number one thing you've done wrong, is the way you asked this question. –  barlop Sep 19 '13 at 12:01
    
now you've shown what you did i've removed the -1. I can see one thing wrong there. With setx and -m, the -m has to be at the end. –  barlop Sep 21 '13 at 23:02

1 Answer 1

Even if you now know what you did wrong. You should still say in your question. Your question is badly asked 'cos you're asking why it is that what you did didn't work and you didn't show exactly what you did. Paste the commands you did.

Here is how one would use setx. This works.

C:\>setx aaa rrr

SUCCESS: Specified value was saved.

Here is proof that it set-

C:\>@REG QUERY "HKCU\Environment"


HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    aaa    REG_SZ    rrr

now if you do set(the command to view the environment variables), the value won't show up. But open a new cmd window and do set, and it shows. It is in the user env variable section. rather than the system one.

For the system environment variable, you need setx aaa 123 -m (i.e. -m at the end), and the location in the registry for system variables, in xp or 7, would be HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and you'd need the cmd prompt in administrative. And watch out with the path you should back it up (setx pathbk "%path%" -m)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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