Jav*_*ier 19 windows environment-variables
gho*_*g74 21
如果要永久设置环境变量,可以将新值插入注册表.例如,使用vbscript,将路径"c:\ test"添加到PATH变量中
Set WshShell = WScript.CreateObject("WScript.Shell")
strReg = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path"
strSetting = WshShell.RegRead(strReg)
strNewSetting = strSetting&";c\test"
WshShell.RegWrite strReg, strNewSetting
Run Code Online (Sandbox Code Playgroud)
因此,如果您使用Python或其他语言,您可以使用您自己的语言自己的api /模块来读写注册表
在C#中,以下内容创建了一个永久环境变量:
Environment.SetEnvironmentVariable("foo", "bar", EnvironmentVariableTarget.Machine);
Run Code Online (Sandbox Code Playgroud)
或者您可以尝试Windows PowerShell脚本; PowerShell默认安装在Windows 7上.
运行powershell.exe
PS C:\> [Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")
Run Code Online (Sandbox Code Playgroud)
然后,例如,从cmd.exe
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\>echo %TestVariable%
Test value.
C:\>
Run Code Online (Sandbox Code Playgroud)
或者(在新的)powershell.exe
PS C:\> echo $ENV:TestVariable
Test Value.
PS C:\>
Run Code Online (Sandbox Code Playgroud)
请访问http://technet.microsoft.com/en-us/library/ff730964.aspx
对于正在寻找快速命令行答案的其他人
SETX 在 Windows 服务器上可用(我认为原生 - http://technet.microsoft.com/en-us/library/cc755104.aspx)
归档时间: |
|
查看次数: |
13697 次 |
最近记录: |