PDA

View Full Version : Environment Variable Problems



GoinOff
06-16-2004, 10:20 AM
Hi,

I have am having a problem with an executable I run in my
intallation. When the executable runs, it doesn't see the
environment variable it needs to read in order to 'do it's thing'.
The environment variable was created earlier in setup
and I can see that it is set correctly. After environment vars
are set, I execute this code to supposedly broadcast the
new environment var to all apps..IT DOESN'T WORK. When
the executable runs, it doesn't see the new environment var.
After a reboot it works fine. The executable also work fine
just after the install by double-clicking the executable. I spent
a few day trying different angles with no luck..How can I get
executables run by my installation to see environment vars
set in the same installation??

Thx,

John

//Flush the NT registry to all applications.
szEnv = "Environment";
pEnv = &szEnv;
SendMessage (HWND_BROADCAST, WM_WININICHANGE , 0, pEnv);

luke_s
06-17-2004, 02:38 AM
The problem is that during the install, you application does not have the new environment and it will only be able to grab this (getenv("ENV")) after the isntall has finished.

Possible ways around this are to run a custom action, and set the environment variable inside this custom action.

e.g

setenv("TEST")
CreateProcess(...)

Or you can re-build the executable to grab the path from the registry instead of using getenv or something similar.

GoinOff
06-17-2004, 11:14 AM
The fact that I can get it from the registry and not from the
environment variable is a bit crazy. You'd think the code
they provide in help examples would do the trick??:

//Flush the NT registry to all applications.
szEnv = "Environment";
pEnv = &szEnv;
SendMessage (HWND_BROADCAST, WM_WININICHANGE , 0, pEnv);

What exacly does this code do??

My install is 100% script so I don't think a custom action will
help my problem. Has anyone solved this problem??

luke_s
06-17-2004, 06:34 PM
I always get confused when run into problems like this so I am not %100 sure, but i think because Windows Installer runs as the System user in a service, this is why is cannot grab the environment variable broadcast.

It needs a new thread to pick up the new environment/

GoinOff
06-18-2004, 09:02 AM
Thanks for your input luke. I tried launching the command
window and executing the program: No Luck!! I also tried
LaunchAppAndWaitEx and also had no luck. Since the
wheels have been spinning a little to long, the exe was
modified with a path flag and now I don't have to worry
about reading the environment variable. I just pass the
path while executing LaunchAppAndWait..

John