Permanently Changing User Environment Variables

by Nov 10, 2011

To create or change an environment variable in the user context, use this low-level call:

[environment]::SetEnvironmentVariable('Test', 12,'User')

This environment variable will keep the value until you change it or delete it – even across reboots. So, it can be used for communication between processes or to keep state across reboots. This is how you read the variable:

[environment]::GetEnvironmentVariable('Test','User')

And to delete the variable, use this line:

[environment]::SetEnvironmentVariable('Test', '','User')

Twitter This Tip!
ReTweet this Tip!