473,807 Members | 2,830 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.Environm ent 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 2749
Hi Eric,

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

ProcessStartInf o psi = new ProcessStartInf o();
...
string name = "some_env_v ar";
string val = "c:\adirectory" ;
psi.Environment Variables[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("kern el32.dll")]
public static extern uint SetEnvironmentV ariable(
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 ProcessStartInf o.EnvironmentVa riables collection. It is readonly but you can get a reference to it and modify the reference directly:
ProcessStartIn fo psi = new ProcessStartInf o();
...
string name = "some_env_v ar";
string val = "c:\adirectory" ;
psi.Environmen tVariables[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("kern el32.dll")]
public static extern uint SetEnvironmentV ariable( 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*******@disc ussions.microso ft.com>
| Sender: <an*******@disc ussions.microso ft.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.publi c.dotnet.genera l
|
| 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
2340
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 version of the same pic. now, it works fine and sometimes when i click on little one it doesn't resize well... this is the code: main.html
1
1654
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 code in C using AVW functions that are licensed by Mayo clinic. In order to access the AVW library of functions, I need to set the
3
1746
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 code in C using AVW functions that are licensed by Mayo clinic. In order to access the AVW library of functions, I need to set the
4
4215
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
2544
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 creates. Is there a way to configure Visual Studio to do this Thanks in advance - Pete H
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
3803
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`` package there is a ``GetEnvironmentVariable``
6
5483
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 22050 -y /home/transla1/public_html/cybertube/web/uploads/video/ generated/31_70_AK000005.AVI.flv '; //exec($str); runExternal($str,$code); echo $code ;
3
2010
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: smitty@localhost ~/proj/mddl4/test $ ./inputs.py {'source_db': '/home/sweet/home.db'} smitty@localhost ~/proj/mddl4/test $ source_db="test_env" ./inputs.py {'source_db': 'test_env'} smitty@localhost ~/proj/mddl4/test $ ./inputs.py -f "test_cli"
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10628
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10373
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9195
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
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 we have to send another system
3
3011
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.