Permanently altering a user's %PATH% environment variable via batch or Python

前端 未结 4 1608
梦毁少年i
梦毁少年i 2021-02-09 00:53

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 prefera

4条回答
  •  遇见更好的自我
    2021-02-09 01:23

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

    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).

    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. :)

    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. ;)

提交回复
热议问题