views:

409

answers:

2

I'm packaging a Python project with setuptools and distributing it with easy_install, which allows me to place an executable file in a Scripts directory, hidden away inside the Python directory. For Linux users who run easy_install as root, there will be added a symbolic link in a standard bin directory (/usr/bin/, iirc). For Windows users, who are much less likely to be comfortable editing such things, there is no such luck.

So, since I've been having difficulty with getting my users to set the PATH 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.

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

+1  A: 

From this website:

Using the add-on tool Setx.exe

It is not part of the standard Windows XP setup but a command-line tool called setx.exe is included in the Windows XP Service Pack 2 Support Tools. This tool extends the set command so that permanent changes in the environment variables can be made. For example, to add a folder C:\New Folder to the path, the command would be

setx path "%PATH%;C:\New Folder"

This sounds like it'll work for what you're wanting to do.

David Archer
+1  A: 

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

Synetech inc.
You still have to have them install SetEnv, but that's a relatively painless procedure. This is looking to be the way I do it.
Xiong Chiamiov
Well you don’t really have to *install* SetEnv, you can just have the executable in the same directory as the BATCH file that does the setting.
Synetech inc.
I finally got around to working on this. Installed SetEnv in wine, pulled out the executable and threw it into my program dir, wrote a batch file to use it, and everything's gravy.
Xiong Chiamiov