I have an application that starts other processes. The app needs to
create/set a few environment variables when a process starts, let the
process run, then remove the environment variables when the process
terminates. Looking through the C# and .NET docs, I've found how to get
environment variables, but not how to create and set them. I found the
EnvironmentPermissions class which grants access, but that's not enough.
Can anyone help me here; the functionality must be out there somewhere!
Thanks.

Hi Ron,
Take a look at Process and ProcessStartInfo classes. Using ProcessStartInfo
you can set envionment variables.
Each process has its own set of envirnment variables so, you don't have to
remove yours when the process terminates

I have an application that starts other processes. The app needs to create/set a few environment variables when a process starts, let the process run, then remove the environment variables when the process terminates. Looking through the C# and .NET docs, I've found how to get environment variables, but not how to create and set them. I found the EnvironmentPermissions class which grants access, but that's not enough. Can anyone help me here; the functionality must be out there somewhere! Thanks.

Thanks, but I've already looked there. Unless the documentation is wrong,
you can only get the values, you cannot set them.
For example, the ProcessStartInfo.EnvironmentVariables property is defined
this way:
public StringDictionary EnvironmentVariables {get;}

I could get some variables and modify the dictionary contents, but then how
do I get them back into the environment if the property does allow a "set"?
For something that should be so simple, there must be a way to do it!

Hi Ron, Take a look at Process and ProcessStartInfo classes. Using
ProcessStartInfo you can set envionment variables. Each process has its own set of envirnment variables so, you don't have to remove yours when the process terminates

I have an application that starts other processes. The app needs to create/set a few environment variables when a process starts, let the process run, then remove the environment variables when the process terminates. Looking through the C# and .NET docs, I've found how to get environment variables, but not how to create and set them. I found the EnvironmentPermissions class which grants access, but that's not enough. Can anyone help me here; the functionality must be out there somewhere! Thanks.

Hi Ron,
You cannot change the invironment on already running process.
The set of envirnoment variables can be only changed upon process creation.

About the EnvironmentVariables property. The property itself is readonly
because it returns StringDictionary (collection) and you cannot set a new
collection. But you can modify (add, delete, change) its content.
Once you compose the set of environment variables you start the new process
using that ProcessStartInfo.
When the process is up and running no one can change its environment except
the process itself.

Thanks, but I've already looked there. Unless the documentation is wrong, you can only get the values, you cannot set them. For example, the ProcessStartInfo.EnvironmentVariables property is defined this way: public StringDictionary EnvironmentVariables {get;}

I could get some variables and modify the dictionary contents, but then
how do I get them back into the environment if the property does allow a
"set"? For something that should be so simple, there must be a way to do it!

I have an application that starts other processes. The app needs to create/set a few environment variables when a process starts, let the process run, then remove the environment variables when the process terminates. Looking through the C# and .NET docs, I've found how to
get environment variables, but not how to create and set them. I found the EnvironmentPermissions class which grants access, but that's not
enough. Can anyone help me here; the functionality must be out there
somewhere! Thanks.

Hi Ron, You cannot change the invironment on already running process. The set of envirnoment variables can be only changed upon process
creation. About the EnvironmentVariables property. The property itself is readonly because it returns StringDictionary (collection) and you cannot set a new collection. But you can modify (add, delete, change) its content. Once you compose the set of environment variables you start the new
process using that ProcessStartInfo. When the process is up and running no one can change its environment
except the process itself.

you can set envionment variables. Each process has its own set of envirnment variables so, you don't
have to remove yours when the process terminates

-- HTH B\rgds 100

"Ron Clarke" <ro********@hp.com> wrote in message news:OK**************@TK2MSFTNGP10.phx.gbl... > I have an application that starts other processes. The app needs to > create/set a few environment variables when a process starts, let

the > process run, then remove the environment variables when the process > terminates. Looking through the C# and .NET docs, I've found how to

get > environment variables, but not how to create and set them. I found
the > EnvironmentPermissions class which grants access, but that's not enough. > Can anyone help me here; the functionality must be out there somewhere! > Thanks. > >