Version 4 of Robust environment variables on Windows

Updated 2005-11-29 19:23:11

Arjen Markus (14 March 2003) Many of my company's programs rely on the presence of environment variables. Sometimes because third-party packages do, sometimes to find our own configuration files, sometimes because the operating system uses them to find the shared/dynamic libraries. (See Extending the DLL Search Path on Windows)

It has been a great sorrow to me that full-scale installation scripts are needed to make such simple things possible as extending the PATH variable under Microsoft Windows and that if you need to do it manually, you have to open any of a wildly varying collection of windows to achieve what you want. It seems so much simpler under Unix. And I have never had "out of environment space" issues there.

The other day, I suddenly realised that there is no need to set these variables in the arcane ways of Windows: just use a small Tcl script. Using Tclkit has additional advantages:

  • No need to install Tcl separately
  • No DOS box appearing

So, instead of defining MYVAR and extending PATH in the System panel, or whatever it is called today, just do:

   set ::env(MYVAR) "Whatever"
   lappend ::env(PATH) "c:/myprogramdir"

   exec myprog.exe &

When the exec command completes, the script is ended and so is Tclkit. But my program is running ...

MHo: This is because the newly executed myprog.exe inherits the environment table from its parent process. P.S.: You don't have to struggle with windows dialogs to manipulate the environment permanently; take a look at the setx.exe-Utility from the resource-kit.


[ Arts and crafts of Tcl-Tk programming - Category Windows ]