Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB & API - GetEnvironmentVariable

Status
Not open for further replies.

sandallj

Programmer
May 25, 2001
2
GB
I need to return the current value of a variable - not the transient version which this API appears to return. i.e. if the env var is changed since the app was executed the change is not picked up. Any ideas on getting the current value of an env var?

Thanks in advance!
 
>the env var is changed

Changed by what? Another program?

Each process in Windows has its own environment block, the initial contents of which are (by default) inherited from the process' parent when the new process is being created; this is the only time that one process can directly affect the environment variables of another process. Changes to values in one process cannot and do not affect the values in the environment block of another process. And GetEnvironmentVariable will only retrieve values from the environment block of the process from which it is called. There are no API calls that will get or set* environment variables in the environment block of another process.

(*actually, this is not 100% true; there is a class of environment variables known as a system environment variables. To programmatically add or modify these, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top