Permanently Changing User Environment Variables

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!


Posted Nov 10 2011, 06:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.