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. 4 12849
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
--
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.
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!
Thanks in advance,
Ron
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl... 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
-- 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.
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.
--
B\rgds
100
"Ron Clarke" <ro********@hp.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl... 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!
Thanks in advance, Ron "Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message news:uG**************@TK2MSFTNGP09.phx.gbl... 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
-- 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.
Aah, that makes more sense. For some reason it did not occur to me that the
contents of the EnvironmentVariables property might be able to be modified.
That's what I need. Thanks.
-Ron
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... 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.
-- B\rgds 100
"Ron Clarke" <ro********@hp.com> wrote in message news:u3**************@TK2MSFTNGP12.phx.gbl... 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!
Thanks in advance, Ron "Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message news:uG**************@TK2MSFTNGP09.phx.gbl... 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
-- 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. > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Greg Lindstrom |
last post by:
Hello-
I am running python 2.3. on an HP-9000 box running Unix and have a POSIX
script that sets up my production environment. I would like to run the
script from inside a python routine and...
|
by: Paul D.Smith |
last post by:
Can Python create a variable "on-the-fly". For example I would like
something like...
make_variable('OSCAR', 'the grouch');
print OSCAR;
....to output...
the grouch
|
by: Christian |
last post by:
Another question from a not even newbie:
In Unix you can set an environment variable with the command
export PYTHONPATH
but I would like to set the variable from at .py script.
So my question...
|
by: Bill Davidson |
last post by:
All:
I've found the 'Environment.GetEnvironmentVariable()' method; but how do I
create and/or set an environment variable?
Thanks,
Bill
|
by: robwharram |
last post by:
Hi,
I'm quite frustrated in the fact that I can't even display a simple
"Hello World" message on .Net. I've been through all of the groups and
searched all over the place and haven't been able...
|
by: Fuzzyman |
last post by:
Hello all,
I would like to set a Windows Environment variable for another
(non-child) process.
This means that the following *doesn't* work : ::
os.environ = value
In the ``win32api``...
|
by: Tristan |
last post by:
Hello community:
I post this because I could not find satisfactory answers in the posts
generated by this nice group.
I work on winXP. I have many little python applications in different
folders,...
|
by: Joe HM |
last post by:
Hello -
I am putting together a little ConsoleApplication that is supposed to
check for an Environment Variable and create it if it does not exist.
I found some code that will add a new...
|
by: smitty1e |
last post by:
Just a fun exercise to unify some of the major input methods for a
script into a single dictionary.
Here is the output, given a gr.conf file in the same directory with
the contents stated below:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |