编程修改环境变量? [英] Programmatically modifiy environment variables?
本文介绍了编程修改环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- Windows 7。
- 这是我自己的机器,所以没有关系,如果它需要管理员权限或某事。
- 最好在Python或.NET中,但如果有必要,我可以学习一些Win32(C / C ++)编程。
推荐答案
如果要永久设置环境变量,可以将新值插入注册表。例如使用vbscript,将路径c:\test添加到PATH变量中
if you want to permanently set environment variable, you can insert the new value into registry. eg with vbscript, add the path "c:\test" into PATH variable
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
如果您使用Python或其他语言,您可以使用您自己的语言自己的api / modules来执行同样的操作来读写注册表。
So, if you use Python or other languages, you can do the same thing using your language's own api/modules to read and write registry
这篇关于编程修改环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文