Environment Variable

  • Thread starter Thread starter Aku
  • Start date Start date
A

Aku

Hello,
In the 'old-days', WIN32-API/MFC, it is possible to create a temporary
key in the registry to satisfy a particular app.
It's done with 'SetEnvironmentVariable(name, value)".
Once the app ceased its activities, the environment vars are
automatically destroyed. It's also contained to that particular app only
- outside of it, they are unknown.

I'm searching a similar method within C#, using
Microsoft.Win32.Registry, but can't find an equivalent.

Somebody knows how?

Regards, Aku.
 
Aku said:
In the 'old-days', WIN32-API/MFC, it is possible to create a temporary
key in the registry to satisfy a particular app.
It's done with 'SetEnvironmentVariable(name, value)".

I don't believe that has anything to do with the registry. It just sets
the environment variables within that process.

You can P/Invoke the same function, of course, and use
Environment.GetEnvironmentVariable to retrieve values.
 
Jon,
You're right! My slip-of-mind, it has NO connection to the registry.
I guess I should rephrase my question to: 'is there a Managed-code
equivalent of 'SetEnvironmentVariable'.
Indeed I can use P/Invoke, but ... I'm wondering why the Environment
method only has a 'Get' and no 'Set' ?

Thanks for your response.
Aku
 
Aku,

The reason for this is that setting an environment variable has a
potential effect across all app domains, and that is something the designers
didn't want people to be able to do (easily, of course). They want'ed to
make the app domain the boundary instead of the process (in which case
setting the environment variable is ok) for the execution context.

Hopet his helps.
 
Back
Top