Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I'm working on Windows 7. How can I permanently add a new path to the 'PATH' environment variable of the current user?

I tried to do so with wmic:

wmic ENVIRONMENT where "name='Path' and username='<%USERNAME%>'" set VariableValue="%Path%;%NEW_FOLDER_PATH%"

The result was:

No Instance(s) Available

And nothing was affected. However if I try with the following with Administrative privilege:

wmic ENVIRONMENT where "name='Path' and username='<system>'" set VariableValue="%Path%;%NEW_FOLDER_PATH%"

It could always succeed.

The NEW_FOLDER_PATH doesn't contain any blank spaces.

How could I resolve this problem?

share|improve this question

marked as duplicate by Karan, AthomSfere, tombull89, Excellll, Shekhar Jul 16 '13 at 13:51

This question was marked as an exact duplicate of an existing question.

    
Do you want to do it programmatically or any way possible? – Mario Jul 15 '13 at 9:55
    
@Mario: Any possible way is acceptable. I'm trying it in a Windows Batch file so this is my most desired way. – yaobin Jul 15 '13 at 10:00
up vote 0 down vote accepted

Played around a bit, and it seems like it expects a domain/computer name together with the user name rather than brackets.

Try running this:

wmic ENVIRONMENT where "name='Path'"

This will return all results, essentially one per user. You'll notice that users use the full name, like Mario-PC\Mario rather than Mario or (what you've tried) <Mario>.

To fix your command line, you'll want to look for the name like that (note the escaped backslash!):

wmic ENVIRONMENT where "name='Path' and username='%USERDOMAIN%\\%USERNAME%'"
share|improve this answer
    
Great! That works! Yeah.. I should have thought of that earlier... – yaobin Jul 15 '13 at 10:53

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