471,046 Members | 808 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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

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
6 5209
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
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
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
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
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
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.

Similar topics

28 posts views Thread by Christian | last post: by
13 posts views Thread by Jimmy Cracker | last post: by
1 post views Thread by Bonj | last post: by
4 posts views Thread by | last post: by
3 posts views Thread by Strauss | last post: by
reply views Thread by =?Utf-8?B?QWlqdW4=?= | last post: by

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.