Process.Start("setenv.bat"); Process.Start("app.exe");Uh oh. No good, because each of the Processes spawn with their own local copy of the environment, and so the environment that is used by app.exe is a fresh copy of the environment used by the .Net app. The easiest solution is to just create another batch file that calls them both and call that instead.
Process.Start("setenv_and_then_call_app_exe.bat");But as soon as it gets more complicated than that, the preferred solution is to run the two in the same environment, which can be done by running a process and redirecting standard input.
Process proc = new Process(); proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardInput = true; proc.Start(); StreamWriter cmdWriter = proc.StandardInput; cmdWriter.WriteLine("setenv.bat"); cmdWriter.WriteLine("app.exe");
Now the changes to the environment made by setenv.bat will persist and affect the execution of app.exe.