Process.Start doesn't pick up new registry and environment variabl

G

Guest

I have the code below, I am spawning two process to run two external
programs, they need to be run in order. the first one will install some
files and registry and environment variables, the second one will do
something else, assuming the registry and env vars are there.

The problem is that the second process doesn't seem to be able to pick up
the registry and env vars done by the first process. The makes me think the
new Process() is not that "NEW". Any idea?

executable = "setup_listener.bat";
process1 = new Process();
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.CreateNoWindow = false;
process1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process1.StartInfo.FileName = executable;
//process1.StartInfo.RedirectStandardOutput = true;
process1.Start();
process1.WaitForExit();

executable = "create_xdb_service.bat";
process3 = new Process();
process3.StartInfo.UseShellExecute = false;
process3.StartInfo.CreateNoWindow = false;
process3.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process3.StartInfo.FileName = executable;
//process3.StartInfo.RedirectStandardOutput = true;
process3.Start();
process3.WaitForExit();
 
S

Steve Alpert

James said:
I have the code below, I am spawning two process to run two external
programs, they need to be run in order. the first one will install some
files and registry and environment variables, the second one will do
something else, assuming the registry and env vars are there.

The problem is that the second process doesn't seem to be able to pick up
the registry and env vars done by the first process. The makes me think the
new Process() is not that "NEW". Any idea?

executable = "setup_listener.bat";
process1 = new Process();
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.CreateNoWindow = false;
process1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process1.StartInfo.FileName = executable;
//process1.StartInfo.RedirectStandardOutput = true;
process1.Start();
process1.WaitForExit();

executable = "create_xdb_service.bat";
process3 = new Process();
process3.StartInfo.UseShellExecute = false;
process3.StartInfo.CreateNoWindow = false;
process3.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process3.StartInfo.FileName = executable;
//process3.StartInfo.RedirectStandardOutput = true;
process3.Start();
process3.WaitForExit();

You can't get there from here. Think of the execution environments
being inherited from the process that starts them. A process gets a
copy of its parent environment and can then change it. When it dies,
the changes die with it.

Setting registry keys should work. Another "kludge" is to create an ini
file in process one and let process two read and then delete it.
Alternatively, why not let the first process continue into the second to
use the same environment?

/steveA
 
E

Ed Kaim

I believe ProcessStartInfo has an EnvironmentVariables property, which you
can use to set env for the second process. The trick will be to get the env
variables out of the first process, which might not be too hard if you can
hardcode or detect during execution. Otherwise, if you own the code from the
first bat, you can have the first process output them and read it from the
managing app by reading from Process.StartInfo.RedirectStandardOutput. It's
kind of a hack, but it works if you're just using it for internal stuff.
 

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