Powershell添加系统变量 [英] Powershell Add System Variable

查看:176
本文介绍了Powershell添加系统变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PowerShell在此处添加系统变量:

I am Trying To add a System Variable here using PowerShell:

我已经尝试过

$env:MyTestVariable = "My test variable."

[Environment]::SetEnvironmentVariable("TestVariableName", "My Value", "<option>")

但是,它们似乎都未添加到本节中.我也尝试过重新启动计算机,以查看它是否会生效.我已经与无数其他网站一起浏览了technet,但没有尝试过.

However neither of them seem to add to this section. I have tried restarting the computer as well to see if it would take effect then. I have looked at technet along with countless other websites, but nothing I have tried has worked.

如何使用PowerShell设置系统变量?

How can I set a system variable with PowerShell?

推荐答案

以管理员身份运行PowerShell(以获取必要的注册表访问权限),然后调出.Net框架进行设置:

Run PowerShell as an administrator (to get the necessary registry access permissions) then call out to the .Net framework to set it:

[Environment]::SetEnvironmentVariable("MyTestVariable", "MyTestValue", "Machine")

NB.它不会在同一过程中生效,您必须创建一个新的PowerShell进程才能看到它.

NB. it won't take effect within the same process, you'll have to make a new PowerShell process to see it.

这篇关于Powershell添加系统变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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