Reputation: 101
I have this script that end all processes but it also terminate windows default processes which cause a blue screen
How can I terminate all processes without this to happen
Process self = Process.GetCurrentProcess() ;
foreach( Process p in Process.GetProcesses().Where( p => p.Id != self.Id ) )
{
p.Kill() ;
}
Upvotes: 2
Views: 57
Reputation: 30665
you need to have whitelist of process names which is not going to be killed. check my example below.
Process self = Process.GetCurrentProcess() ;
IList<string> whiteList = new List<string>() {"svchost.exe", "explorer.exe"....};
foreach( Process p in Process.GetProcesses().Where( p => p.Id != self.Id && !whitelist.Contains(p.ProcessName ) )
{
p.Kill() ;
}
Upvotes: 3