Tutorial :Start another EXE in Managed Code



Question:

Is it possible to start another EXE in Managed Code? At this time, all I can do is use:

System.Diagnostics.Process.Start(exeName)  

Is there another way to call another EXE within the same project?

Thanks! JFV


Solution:1

            Process process = new Process();              process.StartInfo.FileName = "c:\test.exe";              process.StartInfo.Arguments = "/e /s";              process.Start();  

This way you get a lot of options for your process such as process.WaitForExit() so you may not run asynchronously your process, etc.


Solution:2

You could use Assembly.ExecuteAssembly if it is managed. This will execute the main entry point in your current process instead of spinning up a new process.


Solution:3

Use relative paths and it should work.


Solution:4

Relative paths use the CurrentDirectory, a user can easily change this when launching your app and it can change during execution. I'd recommend using something you can be certain about:

There's a lot of different ways to get your executable's path:

AppDomain.CurrentDomain.BaseDirectory    Assembly.GetExecutingAssembly().Location  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »