473,503 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent - Set Environment Variables

I know that i can use the system.Environment namespace to
get environment variables, but how do i go about creating
a new environment variable and setting it's value in .net?
thanks eric.
Jul 21 '05 #1
3 2732
Hi Eric,

If you need to set these in the context of a new Process you are launching,
check out the ProcessStartInfo.EnvironmentVariables collection. It is read
only but you can get a reference to it and modify the reference directly:

ProcessStartInfo psi = new ProcessStartInfo();
...
string name = "some_env_var";
string val = "c:\adirectory";
psi.EnvironmentVariables[name] = val;

Then you can launch your Process with this psi object.

If this context is not useful to you, you could always import the Win32 API
routine to use it:

[DllImport("kernel32.dll")]
public static extern uint SetEnvironmentVariable(
string lpName,
string lpValue );

Then you can call this method from your managed code (you'll need to
declare using System.Runtime.InteropServices).

Hope this helps, let me know if I can provide any more info.

Jeff.

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Jul 21 '05 #2
I should have provided a little more insight into what i
am trying to do. I have a console (vb.net) window that
accepts input, i need to make this input avaliable to the
parent console (windows) window. I figured that
environment variables would do the trick, however i find
that when i edit the registry the machine needs a reboot.
Does this make sense? Any ideas?

thanks eric.

-----Original Message-----
Hi Eric,

If you need to set these in the context of a new Process you are launching,check out the ProcessStartInfo.EnvironmentVariables collection. It is readonly but you can get a reference to it and modify the reference directly:
ProcessStartInfo psi = new ProcessStartInfo();
...
string name = "some_env_var";
string val = "c:\adirectory";
psi.EnvironmentVariables[name] = val;

Then you can launch your Process with this psi object.

If this context is not useful to you, you could always import the Win32 APIroutine to use it:

[DllImport("kernel32.dll")]
public static extern uint SetEnvironmentVariable( string lpName, string lpValue );
Then you can call this method from your managed code (you'll need todeclare using System.Runtime.InteropServices).

Hope this helps, let me know if I can provide any more info.
Jeff.

--

This posting is provided "AS IS" with no warranties, and confers no rights.Use of included script samples are subject to the terms specified athttp://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to thismessage are best directed to the newsgroup/thread from which theyoriginated.

.

Jul 21 '05 #3
Hi, Eric

I wouldn't recommend using environment variables for this purpose. Since
you appear to have control of both the client and the parent applications,
the simplest approach would be a shared database. If you want less
overhead or better reaction speed, I would look at remoting. How you
implement this depends on how your parent app uses the information and how
much information there is. Are the actions of the parent driven by the
console, or does it just collect the data on its own schedule?

Please provide more information and I can do a better job of helping you
target an approach.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| Content-Class: urn:content-classes:message
| From: <an*******@discussions.microsoft.com>
| Sender: <an*******@discussions.microsoft.com>
| References: <01****************************@phx.gbl>
<Br**************@cpmsftngxa06.phx.gbl>
| Subject: RE: Urgent - Set Environment Variables
| Date: Wed, 29 Oct 2003 13:42:21 -0800
| Lines: 66
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I should have provided a little more insight into what i
| am trying to do. I have a console (vb.net) window that
| accepts input, i need to make this input avaliable to the
| parent console (windows) window. I figured that
| environment variables would do the trick, however i find
| that when i edit the registry the machine needs a reboot.
| Does this make sense? Any ideas?
|
| thanks eric.

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2288
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger...
1
1625
by: Rahul S. | last post by:
Hey all: I need urgent information how to set the environment in Visual.NET wiritng in C. I am working with a licensed version of the Analyze 6.0 software from mayo clinic. I need to write...
3
1724
by: Rahul S. | last post by:
Hey all: I need urgent information how to set the environment in Visual.NET wiritng in C. I am working with a licensed version of the Analyze 6.0 software from mayo clinic. I need to write...
4
4200
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
4
2532
by: Pete H | last post by:
I would like to have my new C++ projects start out with two configurations, UnicodeDebug and UnicodeRelease, instead of the standard Debug and Release configurations that Visual Studio always...
3
243
by: Eric | last post by:
I know that i can use the system.Environment namespace to get environment variables, but how do i go about creating a new environment variable and setting it's value in .net? thanks eric.
6
3784
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``...
6
5459
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar...
3
1995
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: ...
0
7278
Oralloy
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,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7458
tracyyun
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...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.