C # Kill all processes that are not essential to run Windows

I have an application. If the application is not used after 15 minutes, it needs to close all other applications (forced closing), and the timer will start again. I do not want to break windows 7 by doing this. So far I have the following:

Process me = Process.GetCurrentProcess(); foreach (Process p in Process.GetProcesses()) { if (p.Id != me.Id && p.ProcessName != "winlogon.exe" && p.ProcessName != "explorer.exe" && p.ProcessName != "System Idle Process" && p.ProcessName != "taskmgr.exe" && p.ProcessName != "spoolsv.exe" && p.ProcessName != "csrss.exe" && p.ProcessName != "smss.exe" && p.ProcessName != "svchost.exe " && p.ProcessName != "services.exe" ) { p.Kill(); } } 

Sadly windowed windows (blue screen). Is there a way to shut down all processes for active use, but hopefully Windows can survive.

+4
source share
4 answers
 if (p.Id != me.Id && !p.ProcessName.ToLower().StartsWith("winlogon") && !p.ProcessName.ToLower().StartsWith("system idle process") && !p.ProcessName.ToLower().StartsWith("taskmgr") && !p.ProcessName.ToLower().StartsWith("spoolsv") && !p.ProcessName.ToLower().StartsWith("csrss") && !p.ProcessName.ToLower().StartsWith("smss") && !p.ProcessName.ToLower().StartsWith("svchost") && !p.ProcessName.ToLower().StartsWith("services") && !p.ProcessName.ToLower().StartsWith("lsass") ) { if (p.MainWindowHandle != IntPtr.Zero) { p.Kill(); } } 

This seems to work.

+1
source

The easiest way to be safe here is to keep a list of the processes that existed when your application started, and exclude those from them. However, depending on when your application starts (for example, if it is not part of the system startup), this may allow some applications to slip through cracks. On the other hand, this will allow user-mode hooks for devices (such as mice and keyboard handlers) to continue working, which means that the system can still be used after you kill everything.

You can try WM_CLOSE translation , although I won’t be surprised if Windows blocks it. This will only affect processes with visible windows, but that may be enough.

The third option is to force ExitWindowsEx from ExitWindowsEx , which will allow the OS to completely shut everything down. Of course, this will also close your own application and force the user to log in again. If you have automatic registration installed, it may be logged in again.

+3
source

First set up autorun on a public PC.

Then your program will simply restart.

Reward points if you set up a steady state or use a product such as Deep Freeze , System Safe , or Time Freeze . These products even have the ability to restart the computer in a clean state after a period of inactivity ...

+3
source

You are probably killing the vital processes necessary for Windows to work. If you kill them, the windows will not be able to recover (as you already understood) and must be rebooted.

+1
source

Source: https://habr.com/ru/post/1340703/


All Articles