The Garbled PATH Variable

Some of you might have already been bitten by this one: After installing a new Delphi version you end up with a garbled PATH variable, simply because the installer tries to extend this variable over some limit. I was not able to find enough reliable information to name this limit, but it might be something about 2000 characters, but this might as well depend on the underlying operating system.

During the setup of a new system with lots of older Delphi versions I decided to write a simple program that uses environment variables to compress the PATH variable so that hopefully it fits when installing the next Delphi version.

The process is plain simple: Check each entry in the PATH variable whether it starts with a given string and replace this with a short environment variable. When finished add those new variables to the environment and write back the shortened PATH variable.

For simplicity I decided to use a single file for this command line utility:

In most cases it should be sufficient to just run the utility as Administrator – otherwise you might not have enough rights to change the registry key in HKEY_LOCAL_SYSTEM. The logic inside InitShortCuts does quite a good job to adapt for different Delphi installations and operating systems. Feel free to add more settings for the missing Delphi versions and leave a comment with your extensions.

The mechanism is not restricted to Delphi pathes and can easily be expanded for other programs. Method InitShortCuts has an example for SQL server and Program Files in general.

If your needs are a little bit more special you can prepare a specific shortcut file that can be loaded via the /F command line parameter. For an example of such a file simply specify the /X command line parameter together with a file name to get the default settings exported.

This program is written with Delphi XE7 and probably uses some language features that may not be available in previous Delphi versions. Nevertheless, it should be not that hard for you to backport those constructs.

Author: Uwe Raabe

Addicted to Pascal/Delphi since the late 70's