通过批处理或Python永久更改用户的%PATH%环境变量 [英] Permanently altering a user's %PATH% environment variable via batch or Python

查看:127
本文介绍了通过批处理或Python永久更改用户的%PATH%环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让我的用户手动设置PATH环境变量,我正在寻找一种自动执行此操作的方法。一个批处理文件是最好的,因为这将需要它们自己运行(有关于他们在做什么的警告),但除了 setup.py 也可以接受。

I've been having difficulty with getting my users to set the PATH environment variable manually, I'm looking for a way to do this automatically. A batch file would be preferable, since that would require them to run it themselves (with a warning as to what they're doing), but an addition to the setup.py is acceptable as well.

其他信息: SET 仅影响当前和衍生外壳;永久性的价值似乎存储在注册表中(我不敢踩踏的地方)。

Other information: SET only affects the current and derivative shells; the permanent values seem to be stored in the Registry somewhere (a place where I dare not tread).

推荐答案

正如大卫所说,有可以从Windows资源工具包中获取的SETX工具。

As David said, there is the SETX tool that you can get from the Windows Resource Kit.

但是,我发现SETX有时会有问题(比如崩溃)。我没有弄清楚问题是什么,但我怀疑它是一个大小问题(例如,如果你尝试设置一个变量,我的情况是PATH)到一个太大的值,例如> 1024一些奇怪字符)。

However, I have found that SETX has trouble (like crashing) sometimes. I have not figured out exactly what the problem is, but I suspect it is a size issue (for example if you try to set a variable—in my case it was PATH—to a value that is too big, eg >1024 some odd characters).

我发现了另外两个可以做同样事情的可执行文件。我最喜欢的是 SetEnv by JonathanDarkaWilkes over CodeProject。他使它非常有用,具有良好的功能,并且与所有Windows系统兼容 - 我也提出了一些功能。 :)

I have found two other executables that can do the same thing. My favorite in particular is SetEnv by Jonathan "Darka" Wilkes over at CodeProject. He has made it quite useful, with good functionality, and it is compatible with all Windows systems—I suggested some features too. :)

另一个选项,如果你要做到这一点,手动做(实际上将该项目添加到注册表,然后播放一个WM_SETTINGCHANGE 到顶级窗口,或重新启动shell /重新启动)。不过我认为在BATCH文件中的SetEnv是你最好的选择。 ;)

Another option, if you are up to it, is to do it manually (actually adding the item to the registry and then either broadcasting a WM_SETTINGCHANGE to top-level windows, or restarting the shell/rebooting). However I think that SetEnv in a BATCH file is your best bet. ;)

这篇关于通过批处理或Python永久更改用户的%PATH%环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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