Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
so in my program i use EnumProcess to get all active processes and then compare this ID's with a file and if i find the same ID i terminate it ,
my problem now is how to terminate the program , should i use TerminateProcess ? is there any easier and safer method ? and ty
Afzaal Ahmad Zeeshan 28-Aug-15 15:22pm    
Code please?
Member 11943312 28-Aug-15 15:38pm    
i can give you but its a total mess right now as i didnt finish most of the things
Afzaal Ahmad Zeeshan 28-Aug-15 15:44pm    
Not just me, update your question by clicking on Improve question, then add the code that is relevant to the question.

It helps us to determine what sort of problem you are in and what can we do to help you.
Sergey Alexandrovich Kryukov 28-Aug-15 15:52pm    
I don't see the problem in code; the inquirer probably knows how to terminate the process and just asking for an advice. The main problem is really "why doing so?" I already answered with Solution 1, which can be clarified is we get some more specific clarifications from the inquirer.
Sergey Alexandrovich Kryukov 28-Aug-15 15:50pm    
Why doing so?

Of course, you can use TerminateProcess, and this is not even so dangerous (compared to TerminateThread), but this is certainly a dirty thing to be used only in extreme cases; for example, OS can terminate faulty process. In regular use, the process should terminate itself, just by returning from its entry-point function. It should work this way even if you decide to terminate process on some fatal exception, but even this is rare and use mostly in simplest console-only utilities.

External termination of some process is always the abuse, unless we are talking about system utilities for process control, which can be done in emergency situations, debugging/troubleshooting and other experimental situations. Doing so means dealing with the processes not properly designed for termination in civilized graceful ways.

Share this answer
CPallini 28-Aug-15 16:23pm    
Sergey Alexandrovich Kryukov 28-Aug-15 16:39pm    
Thank you, Carlo.
In addition to Sergey's advice, have a look at "How to gracefully terminate a process?" at Stack Overflow[^].
Share this answer
Sergey Alexandrovich Kryukov 28-Aug-15 16:39pm    
Yes, a good link, a 5.
Member 11943312 29-Aug-15 4:20am    
Thank you

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