I want to make in my program the function of tracking processes and closing the program when they are detected, namely sniffer packages that track sent requests. I know what to do is useless, but from the lamers such a simple defense would be fine with me.
Sketched such a simple code:
static void KillThemAll() { while (true) { if ((Process.GetProcessesByName("FirstProgram").Length > 0 || Process.GetProcessesByName("SecondProgram").Length > 0 || Process.GetProcessesByName("ThirdProgram").Length > 0) || Environment.HasShutdownStarted || FindWindow("", "FourProgram") != IntPtr.Zero || FindWindow("", "FiveProgram") != IntPtr.Zero) { Environment.Exit(0); } Thread.Sleep(1000); } }
Further after InitializeComponent();
I use my KillThemAll();
function KillThemAll();
and trying to run a program. Closing processes is fine, but the interface does not appear. Apparently due to while(true)
my code becomes unreachable. But how to fix it and make my ideas work? I hope for your suggestions.
Process p
process inside the loop. So do you need this cycle at all? - tym32167