Link to home
Start Free TrialLog in
Avatar of dkathuria
dkathuria

asked on

Programmtic way to set "PATH" in Windows 2000

I am looking for a programmtic way in C++ to set an env variable (PATH) that applies to all processes / console prompts started *after* my program finishes
Avatar of jkr
jkr
Flag of Germany image

Your only chance to do so is using the registry and adding/modifying entries under

HKEY_CURRENT_USER\Environment

or

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooops - make

   HKEY hBase = bSystem : HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;

read

   HKEY hBase = bSystem ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
Avatar of dkathuria
dkathuria

ASKER

Thanks. But the problem here is that it does not take into effect until I reboot the system. I am looking for some solution where as soon as I update the registry, other processes can use it.
Rebooting should not be necessary - that is exactly the way it is handled when you alter user/system environment variables using the "My Computer" properties...
Dont use the registry but use the 'DOS' prompt.
Execute SET PATH
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Arrg!  Thought I was in the VB area....  :-)

The code should of course be like this:

DWORD Result;

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", SMTO_ABORTIFHUNG, 5000, &Result);