close exe

04/05/2010 06:57 zTREME#1
how can i make it close an exe file thats open:
ex. if console.exe run
close console.exe

because then the restart will never fail, cuz i make it close the console first.
04/05/2010 10:28 ~Yuki~#2
if u close the console first it would not start the server anymore ^^
04/05/2010 11:45 Arcо#3
Environment.Exit(0);

That what you mean?
04/05/2010 12:15 PeTe Ninja#4
or

Code:
Environment.Exit(Environment.ExitCode);
xD
04/05/2010 19:06 Arcо#5
I think basically what he wants to do is
Environment.Exit(0);
Process.Start("ProcessName.exe");
Not sure if the process one is correct.
04/05/2010 19:18 _tao4229_#6
Wait, are you trying to close your own process, or close a process from a different one?
To close the process thats running that code:
Code:
Environment.Exit(Environment.ExitCode);
Else you need to do something like this
(using System.Diagnostics; )
Code:
foreach (Process process in Process.GetProcessesByName("console"))
{
    process.Kill();
}
To start a process use
Code:
Process.Start("console.exe"); // this also returns an instance of the class Process by which you can do other things