Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Application Process WinForm , +
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 19:02pm
Comments
SAKryukov at 10-May-12 0:04am
   
Why?! why?
--SA
JF2015 at 10-May-12 0:10am
   
Sounds like you are trying to program malware :(
MR. AngelMendez at 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.
SAKryukov at 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 at 10-May-12 1:43am
   
how about closing any windows that are behind my full screen window?
SAKryukov at 10-May-12 19:10pm
   
You can do it (why?) -- please see Solution 2.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 10-May-12 0:32am
   
The first paragraph of your answer worth a appreciation :)
SAKryukov at 10-May-12 1:35am
   
Thank you, Mohammad.
--SA
MR. AngelMendez at 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?
SAKryukov at 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 at 11-May-12 1:19am
   
5!
SAKryukov at 11-May-12 10:36am
   
Thank you, Monjurul.
--SA
VJ Reddy at 11-May-12 11:52am
   
Good answer. 5!
SAKryukov at 11-May-12 11:58am
   
Thank you, VJ.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

[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  
v2
Comments
Monjurul Habib at 11-May-12 1:19am
   
5!
SAKryukov at 11-May-12 10:36am
   
Thank you, Monjurul.
--SA
VJ Reddy at 11-May-12 11:52am
   
Good references. 5!
SAKryukov at 11-May-12 11:59am
   
Thank you, VJ.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 12 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100