To programmatically change an Environment variable from within your application, you can use one of the following three commands:
Setting the environment variable for only the current process:
Environment.SetEnvironmentVariable("<VarName>", "<VarValue>", EnvironmentVariableTarget.Process);
Setting the environment variable for the current user:
Environment.SetEnvironmentVariable("<VarName>", "<VarValue>", EnvironmentVariableTarget.User);
Setting the environment variable for the entire system:
Environment.SetEnvironmentVariable("<VarName>", "<VarValue>", EnvironmentVariableTarget.Machine);
Additional information on Environment.SetEnvironmentVariable()
with examples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.