Quote Originally Posted by Mehdi Jazini View Post
do you know WAMPSERVER?
No.

Quote Originally Posted by Mehdi Jazini View Post
i have 32 bit version of it.
when i do right click on the (system try icon) of it and click (Exit)... the WAMP SERVER program will try to close (itself) + (all hidden opened programs related to the wamp... like: httpd.exe and etc...)
but your code will try to close wampmanager.exe only
yes tried to close wampmanager.exe in safe mode, but it couldn't execute (Exit) command in WAMP SERVER program.
In your OP, you failed to mention that you wanted to terminate the child processes too. I had no way of knowing what you really required, hence the code in post #4 didn't take that into account. In order to prevent further confusion, can you please describe your requirements in utmost detail? Thank you. (When composing an OP, you should always divulge as much information as possible about the problem.)

Quote Originally Posted by Mehdi Jazini View Post
i have a suggestion... if we do convert hProcess to hwnd, we can use PostMessage function for this. but i don't know how to convert it hProcess is an argument of TerminateProcess function:
In the code above, I've replaced the PostMessage function with the SendMessageTimeout function so that the code will wait a certain amount of time for the WM_CLOSE message to be processed by the target window. This synchronous approach simplifies the code a bit by eliminating the WaitForSingleObject function.

Here's what the code above does:

  1. All the top-level windows (those that are neither a child control nor owned window) are enumerated.
  2. Each window's Process ID is obtained so that its process can be opened.
  3. The fully-qualified pathname of the process is retrieved and the filename component is extracted.
  4. The process' filename is compared (using the Like operator) against the specified ImageName.
  5. If the names match, the current window is requested to close via the WM_CLOSE message.
  6. If the window failed to close within the designated time limit, the code then attempts to forcibly terminate the window's process.
  7. Steps 2-6 are repeated for the other windows whose processes matches the specified ImageName, if any.


Are you saying you want to do the reverse? That is, enumerate the windows of a given process? Well, it can be done through the CreateToolhelp32Snapshot, Thread32First, Thread32Next and EnumThreadWindows functions.