I am trying set environment variables that can be used in an XP
command batch file by other programs from within my console app:

MyDelphiApp.exe MyParameter
AnotherApp.exe c:\somepath\%myEnvVar%\somefile.xxx


The object is for MyDelphiApp to set environment variables such as
"MyEnvVar" in a way that can be used by other programs in the batch,
or on the command line such as %myEnvVar% in my example.

I tried the technique showed here:
http://www.swissdelphicenter.ch/torry/showcode.php?id=1394, but the
registry-based changes do not affect a running batch file in a CMD
window (only after reboot, or logoff/logon). In addition, the CMD
window does not seem to respond to the SendMessage(HWND_BROADCAST....
that is supposed to update the current environment. Placing a SET
command before and after MyDelphiApp.exe shows no change in the
environment. 

If a simple SET command in a batch file can set an environment
variable, isn't there an API from a program that can do the same
thing? I know this was possible in the TP/DOS days - was it eliminated
with NT/2K/XP? 

For now, I'm using a workaround where MyDelphiApp writes a new batch
file containing SET commands, which is then called by the main batch
file. It's ugly, but seems to work. I would still like to understand
how to properly write environment variables from a program. 



Reply via email to