使用powershell将环境类型设置为reg_expand_sz [英] Setting Environemnt Type to reg_expand_sz using powershell

查看:228
本文介绍了使用powershell将环境类型设置为reg_expand_sz的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入了一个问题。我正在尝试使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆