Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
1.80/5 (5 votes)
Hi, I am making a simple application that is supposed to clear all running exe applications. My question is, how do you taskkill all applications except my program?

thanks,


operating system windows 7

visual C#, winform
Posted
Comments
Sergey Alexandrovich Kryukov 10-May-12 0:04am    
Why?! why?
--SA
JF2015 10-May-12 0:10am    
Sounds like you are trying to program malware :(
MR. AngelMendez 10-May-12 1:34am    
I'm making a custom login program that prompts the user to put in a password at the startup. I don't want the user to be able to stop my program by using command prompt, task manager or be able to use the computer without putting in the password. If there is another method of doing the desired result then please let me know.

NOTE: so far I got a blank, full screen, topmost window that covers everything. I also have the login form that prompts the user for the password. it is a modal form so you cannot click anywhere but the user is able to use the keyboard to navigate out.

I know this program is reinventing the wheel but I'm doing this for practice.

I appreciate everyone's comments and help. I also respect everyone's concern.
Sergey Alexandrovich Kryukov 10-May-12 1:39am    
One thing you won't be able to stop or prevent to activate is the Task Manager. The OS treat this process in a special way. In particular, it is not possible to intercept Ctrl+Alt+Del, even though you can intercept any other key combination. Interesting, isn't it?
--SA
MR. AngelMendez 10-May-12 1:43am    
how about closing any windows that are behind my full screen window?

I hope you won't be able to kill them all, it cannot make any sense, anyway, but why would I care if you want to screw up your system? You will reboot it (because you hardly will be able to work at all if you kill some of the critically important applications).

Whatever. Those are not applications, but processes. You can get all processes using System.Diagnostics.Process.GetProcesses and kill a process using System.Diagnostics.Process.Kill. Please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

This is all you need, enjoy. Let the OS doomsday begin!

—SA
 
Share this answer
 
Comments
Mohammad A Rahman 10-May-12 0:32am    
The first paragraph of your answer worth a appreciation :)
Sergey Alexandrovich Kryukov 10-May-12 1:35am    
Thank you, Mohammad.
--SA
MR. AngelMendez 10-May-12 1:40am    
so I can't just target applications like in the task manager where it only lists applications in the application tab?
Sergey Alexandrovich Kryukov 10-May-12 12:30pm    
What is "application tab"? It just list all processes in the system. I head that there is a way to hide a process, so maybe not all of them.
Just try it to see; it would be only few lines of code...
--SA
Monjurul Habib 11-May-12 1:19am    
5!
[Answering the follow-up question, from the comment to the original question:]

MR. AngelMendez wrote:
How about closing any windows that are behind my full screen window?

Of course you do it but why? It won't solve your problem.

Anyway, you can use Windows API to get HWND of a desktop and then its children, those placed in certain Z-order relative to your window. Then you can compare this list with the result of the call to System.Diagnostics.Process.GetProcesses, using System.Diagnostics.Process.MainWindowHandle, please see http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx[^].

This way, you can kill only the selected processes.

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633504%28v=vs.85%29.aspx[^] (to find desktop),
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633515%28v=vs.85%29.aspx[^] (to find its children),
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633509%28v=vs.85%29.aspx[^] (to find windows in certain Z-order).

If you need to use P/Invoke, please see:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[^].

This CodeProject article can also be useful:
Essential P/Invoke[^].

—SA
 
Share this answer
 
v2
Comments
Monjurul Habib 11-May-12 1:19am    
5!
Sergey Alexandrovich Kryukov 11-May-12 10:36am    
Thank you, Monjurul.
--SA
VJ Reddy 11-May-12 11:52am    
Good references. 5!
Sergey Alexandrovich Kryukov 11-May-12 11:59am    
Thank you, VJ.
--SA
Listen up.
You can make a for loop or foreach loop that loops in the current processes, and then check the handle of each process and compare it with your application's.
What you will face as a problem is that you can't kill all the processes, because some of them are you graphics card's and some are from your system.
for example, if you're using windows, if you try to terminate a process like system.exe (if you succeed in this. Probably will give you a permission error) you're PC will reboot. So I think you should try to find another way.
 
Share this answer
 
Why not just delete all your system files will save you time in messing up the system.....just a thought.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900