41

I'd like to set a temporary enviroment variable in windows CMD line, which in my word the windows shell. because it's for temporary usage, So I don't want to add a new enviroment variable system wise by clicking "my computer-->properies---" ...

by the way, the envrioment variable I'd like to set is http proxy, but I don't known the windows syntax for that. so if you happen to know it as well, please tell me and I'll apreciate you even more ...

3 Answers 3

55

To set a temporary or 'per session' environment varible from a command line you can use:

set ‹var name›=‹value>

Make sure your spacing is exactly as shown above, if you add a space between the equal sign the command will fail.

Check: Link for a nice tutorial and info on environment variables.

3
  • 4
    It's not so much per session as per process and child process. Other processes already running in your login session will not see this new (or changed) variable, only the current cmd.exe process and any processes launched from it. Commented Nov 18, 2010 at 8:22
  • 2
    Sorry, with session I meant the current process; I just noticed that calling it session may be a bit confusing. Commented Nov 19, 2010 at 13:59
  • It's interesting to note that variable names may contain spaces (at least with this method), so if you add a space, that gets added to the variable name. Strange. Commented Apr 27, 2018 at 14:20
18

If you are using PowerShell, then you need to use the $env prefix for creating an environment variable.

Here's an example:

$env:<var name> = '<value>' 
1
  • 3
    Question state "windows CMD line", not PowerShell Commented Sep 13, 2018 at 16:42
11
SET VAR_NAME=value 

See the Microsoft Documentation for the details.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.