how can i add environment variable to my VS.NET 2003 project ?

G

Guest

Hi,

my application use environment variable, let call it FOO.

how can i add the FOO environment variable to my project or my solution,

so the line

string foo = Environment.GetEnvironmentVariable("FOO");

will work ?

Thanks.
 
D

David Levine

The process that launches your application must set the environment variable
before it launches your application. For example, you can write a simple
batch file that sets the environment variable and then launches your
executable. It can be as simple as...

set FOO=SomeValue
MyApp.exe
 
G

Guest

i forgot to tell a few details :
the problem i need to solve is to run 2 instances of my sample app
simultaneously from the folder with 2 different app configurations. so FOO is
the name of myconfig.xml file.

1. i need to be able to run my project from Visual Studio.NET 2003, so i
don't know how to this set FOO=SomeValue inside the Visual Studio IDE and not
from outside batch file. so every time the user want to change FOO value he
will change it and then press F5 (Run) from the VS.NET without the need to
leave or restart the IDE.

2. the user need to run 2 instances simultaneously of my sample application
with different values for FOO from the same sample app folder.

3. without using Main args[] parameters array ?

shortly something like VM paramerers in java.

Thanks.
 
M

Michael Nemtsev

Hello yaron,

Use Environment.SetEnvironmentVariable for .NET 2.0 or P/Invoke
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool SetEnvironmentVariable(string lpName, string lpValue);

y> Hi,
y> my application use environment variable, let call it FOO.
y> how can i add the FOO environment variable to my project or my
y> solution,
y> so the line
y> string foo = Environment.GetEnvironmentVariable("FOO");
y> will work ?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
G

Guest

can i set environment variable in the Visual Studio.NET 2003 IDE or in the
Visual Studio project properties ? or start debuging from a batch file ?

Thanks.
 
M

Michael Nemtsev

Hello yaron,

Nope. U can't change machine settings from the VS IDE, but u can call some
app in Pre/Post build action, where your machine settings will be set.


y> can i set environment variable in the Visual Studio.NET 2003 IDE or
y> in the Visual Studio project properties ? or start debuging from a
y> batch file ?
y>
y> Thanks.
y>
y> "Michael Nemtsev" wrote:
y>
Hello yaron,

Use Environment.SetEnvironmentVariable for .NET 2.0 or P/Invoke
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool SetEnvironmentVariable(string lpName, string
lpValue);
y> Hi,
y> my application use environment variable, let call it FOO.
y> how can i add the FOO environment variable to my project or my
y> solution,
y> so the line
y> string foo = Environment.GetEnvironmentVariable("FOO");
y> will work ?
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
G

Guest

Hi Michael,

if before loading VS IDE my environment variable FOO==aaa, then in the pre
or post build event i will write the command SET FOO=bbb then i will run the
program from the VS IDE (Ctrl^F5) would i see the new value for FOO which is
bbb ?
or maybe there is other trick to cause the running program from the IDE to
see the new value for FOO ?

Thanks a lot.


Michael Nemtsev said:
Hello yaron,

Nope. U can't change machine settings from the VS IDE, but u can call some
app in Pre/Post build action, where your machine settings will be set.


y> can i set environment variable in the Visual Studio.NET 2003 IDE or
y> in the Visual Studio project properties ? or start debuging from a
y> batch file ?
y>
y> Thanks.
y>
y> "Michael Nemtsev" wrote:
y>
Hello yaron,

Use Environment.SetEnvironmentVariable for .NET 2.0 or P/Invoke
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool SetEnvironmentVariable(string lpName, string
lpValue);
y> Hi,
y> my application use environment variable, let call it FOO.
y> how can i add the FOO environment variable to my project or my
y> solution,
y> so the line
y> string foo = Environment.GetEnvironmentVariable("FOO");
y> will work ?
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top