473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2720
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...

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.