Click here to Skip to main content
Sign Up to vote bad
good
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 9 May '12 - 18:02

Comments
SAKryukov - 10 May '12 - 0:04
Why?! why? --SA
JF2015 - 10 May '12 - 0:10
Sounds like you are trying to program malware :(
MR. AngelMendez - 10 May '12 - 1:34
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.
SAKryukov - 10 May '12 - 1:39
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:43
how about closing any windows that are behind my full screen window?
SAKryukov - 10 May '12 - 19:10
You can do it (why?) -- please see Solution 2. --SA

4 solutions

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
  Permalink  
Comments
Mohammad A Rahman - 10 May '12 - 0:32
The first paragraph of your answer worth a appreciation :)
SAKryukov - 10 May '12 - 1:35
Thank you, Mohammad. --SA
MR. AngelMendez - 10 May '12 - 1:40
so I can't just target applications like in the task manager where it only lists applications in the application tab?
SAKryukov - 10 May '12 - 12:30
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:19
5!
SAKryukov - 11 May '12 - 10:36
Thank you, Monjurul. --SA
VJ Reddy - 11 May '12 - 11:52
Good answer. 5!
SAKryukov - 11 May '12 - 11:58
Thank you, VJ. --SA
[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
  Permalink  
Comments
Monjurul Habib - 11 May '12 - 1:19
5!
SAKryukov - 11 May '12 - 10:36
Thank you, Monjurul. --SA
VJ Reddy - 11 May '12 - 11:52
Good references. 5!
SAKryukov - 11 May '12 - 11:59
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.
  Permalink  
Why not just delete all your system files will save you time in messing up the system.....just a thought.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,386
1 OriginalGriff 6,596
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 12 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid