views:

202

answers:

2

i need to close all open applications in windows while my application closes how to i do that using c#

i am implementing login/logoff functionality in my application itself instead of windows login/logoff so that i need to close all applications while logoff clicked in my application and pass control to my application after that

A: 
using System.Diagnostics;

Process [] localAll = Process.GetProcesses();
foreach(Process p in localAll)
{
    p.Kill();
}

But you'd probably have to put in some kind of filter to avoid killing certain processes since otherwise the machine might get a bit upset.

ho1
the "might get a bit upset"-part made my day: thx!
riffnl
A: 

For whatever reason you want to do this. This is a bit funnier way to do it!

using System.Diagnostics;

Parallel.ForEach(Process.GetProcesses(), process => process.Kill());

Don't run this with an elevated process though; will probably caus your OS to crash.

Filip Ekberg
That's just too much fun.
jcao219