|
-
Feb 18th, 2014, 09:27 AM
#6
Re: Normal Termination of an external program using VB6
 Originally Posted by Mehdi Jazini
do you know WAMPSERVER?
No.
 Originally Posted by Mehdi Jazini
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.)
 Originally Posted by Mehdi Jazini
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:
- All the top-level windows (those that are neither a child control nor owned window) are enumerated.
- Each window's Process ID is obtained so that its process can be opened.
- The fully-qualified pathname of the process is retrieved and the filename component is extracted.
- The process' filename is compared (using the Like operator) against the specified ImageName.
- If the names match, the current window is requested to close via the WM_CLOSE message.
- If the window failed to close within the designated time limit, the code then attempts to forcibly terminate the window's process.
- 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.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|