I am stuck on a issue. I am trying to set user-environment variables using PowerShell:
[Environment]::SetEnvironmentVariable($key,$value,'User')
But when I look into the registry I can see the new entry is of type REG_SZ
.
I would like it to be of type REG_EXPAND_SZ
.
Can someone help me with this problem?
Use the Microsoft.Win32
namespace for Registry methods. To set the data type, use RegistryValueKind enumeration. Like so:
[Microsoft.Win32.Registry]::SetValue("HKEY_CURRENT_USER\Environment","MyKey","1",[Microsoft.Win32.RegistryValueKind]::ExpandString)
User variables are located in HKEY_CURRENT_USER\Environment
System variables are located in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With