set environment variables

  • Thread starter Thread starter Agostino
  • Start date Start date
A

Agostino

How do I set a system environment variable programmatically?
Is there any api call?
Thanks
Agostino
 
Agostino said:
How do I set a system environment variable programmatically?
Is there any api call?

If you're trying to set a system environment variable for all programs,
you can't use SetEnvironmentVariable but need to set a value under the key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment where the name of the value is the name of the variable
and the data is a REG_EXPAND_SZ string (if you make it REG_SZ, environment
variables within it may not be properly expanded).

For completeness, environment variables for the current user are contained
in the key HKEY_CURRENT_USER\Environment.
 
Back
Top