By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,574 Members | 1,205 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,574 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Feb 21 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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.

Feb 21 '06 #2

P: n/a
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.
"David Levine" wrote:
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

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
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.


Feb 21 '06 #3

P: n/a
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
Feb 21 '06 #4

P: n/a
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.
"Michael Nemtsev" wrote:
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

Feb 21 '06 #5

P: n/a
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
Feb 21 '06 #6

P: n/a
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" wrote:
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

Feb 22 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.