Setting Environment Variable from VB.NET

Hello,

I have an Environment variable named "PAR" which has value "plan".

Now i open 2 command prompt..

In first command prompt..
I run my exe which uses Original Environment variable..
In Second command prompt.
I set the value for Enviroment variable as "planned" and for the execute the
my exe which uses new Environment...

When Both the command prompt are closed and we see the Environment
variable value and i.e. same as set original...
I want to perform the same process with my VB.NET application.

What i am doing is calling Process.Start() method to execute the EXE but..
I need to change the Environment Variable for the current Instance..

Any Ideas how to achieve this.

Regards
Amit Pandya

[765 byte] By [AmitPandya] at [2007-12-16]
# 1
If you want to set environment variable values before calling Process.Start() you use the StartInfo property to get access to the environment variable.

For example the following code defines an environment variable called 'foo' and sets it to the value "C:\" for the process initiated by shell.Start(). To make things easy shell.Start runs cmd.exe so you can use set foo to see the environment variable


Dim startInfo As ProcessStartInfo

startInfo = New ProcessStartInfo

startInfo.EnvironmentVariables("foo") = "C:\"

startInfo.FileName = "cmd.exe"

startInfo.UseShellExecute = False

Dim shell As Process

shell = New Process

shell.StartInfo = startInfo

shell.Start()


FrankBoyne at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Hi Frank,

Thanks for the answer.

With the help of your answer i successfully done the work.

Regards
Amit Pandya

AmitPandya at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified