使用powershell将环境类型设置为reg_expand_sz [英] Setting Environemnt Type to reg_expand_sz using powershell
问题描述
[Environment] :: SetEnvironmentVariable($ key,$ value,用户')
但是当我查看注册表时,我可以看到新条目的类型为code> REG_SZ 。
我希望它是类型 REG_EXPAND_SZ
有人可以帮我解决这个问题吗?
谢谢
使用Microsoft.Win32命名空间注册表方法的。要设置数据类型,请使用 RegistryValueKind 枚举。像这样,
[Microsoft.Win32.Registry] :: SetValue(HKEY_CURRENT_USER\Environment,MyKey, 1,[Microsoft.Win32.RegistryValueKind] :: ExpandString)
用户变量位于HKEY_CURRENT_USER\\ \\环境
系统变量位于HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
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?
Thanks
Use 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
这篇关于使用powershell将环境类型设置为reg_expand_sz的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!