set environment variables

A

Agostino

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

Gary Chanson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top