I was trying to use the sentence
Environment.SetEnvironmentVariable("CLIENTIP", <value>)
but the variable is not created. I used both an string variable and a constant to set the value.
So, how can I do this to work?
I was trying to use the sentence
Environment.SetEnvironmentVariable("CLIENTIP", <value>)
but the variable is not created. I used both an string variable and a constant to set the value.
So, how can I do this to work?
Can you explain what you mean by didn't work? That code will certainly set the environment variable CLIENTIP for the current process.
If you wanted to set it more broadly you're going to have to use a different overload of the SetEnvironmentVariable
method.
Environment.SetEnvironmentVariable(
"CLIENTIP",
value,
EnvironmentVariableTarget.Machine);
The EnvironmentVariableTarget
parameter lets you target the process, machine or current user.
Note: These changes likely won't show up in existing processes as not all types of processes respond to this change immediately (cmd.exe is one that comes to mind). But it will show up on future processes.