Terminate an exe from another exe ?
-
Hello Friends I have an application in which I need to start one exe from another one and at the end when the first one ends, it should automatically end the second one. To start I use ShellExecute() or WinExec() function. And to terminate the another exe I put code into the destructor of the first one from where I have started it. But the problem is I don't know the Handle of the new exe that I have started using ShellExecute() or WinEec()..... Is there any functions which can give me the Handle of a perticular window or is there any other way to stop the application without knowing the handle or process id ? Thankx in advance My Code Looks Like : ------------------- My first.exe file ================ MyClass() { // Do some work here........ WinExec("C:\\Temp\\second.exe",SW_SHOW); // Do some work here... }; ~MyClass() { Here I want to kill(Terminate) the second.exe } Any help plz ? Thankx } } Amarelia Maehsh Gujarat India
-
Hello Friends I have an application in which I need to start one exe from another one and at the end when the first one ends, it should automatically end the second one. To start I use ShellExecute() or WinExec() function. And to terminate the another exe I put code into the destructor of the first one from where I have started it. But the problem is I don't know the Handle of the new exe that I have started using ShellExecute() or WinEec()..... Is there any functions which can give me the Handle of a perticular window or is there any other way to stop the application without knowing the handle or process id ? Thankx in advance My Code Looks Like : ------------------- My first.exe file ================ MyClass() { // Do some work here........ WinExec("C:\\Temp\\second.exe",SW_SHOW); // Do some work here... }; ~MyClass() { Here I want to kill(Terminate) the second.exe } Any help plz ? Thankx } } Amarelia Maehsh Gujarat India
You could use CreateProcess() and TerminateProcess(), however TerminateProcess() ends a program so abruptly that some applications don't handle it well, it doesn't give them time to save their settings or other exit code. I'd recommend using FindWindowEx() and sending a WM_CLOSE to the main window.
-
You could use CreateProcess() and TerminateProcess(), however TerminateProcess() ends a program so abruptly that some applications don't handle it well, it doesn't give them time to save their settings or other exit code. I'd recommend using FindWindowEx() and sending a WM_CLOSE to the main window.
PostQuitMessage is another way. The tigress is here :-D
-
Hello Friends I have an application in which I need to start one exe from another one and at the end when the first one ends, it should automatically end the second one. To start I use ShellExecute() or WinExec() function. And to terminate the another exe I put code into the destructor of the first one from where I have started it. But the problem is I don't know the Handle of the new exe that I have started using ShellExecute() or WinEec()..... Is there any functions which can give me the Handle of a perticular window or is there any other way to stop the application without knowing the handle or process id ? Thankx in advance My Code Looks Like : ------------------- My first.exe file ================ MyClass() { // Do some work here........ WinExec("C:\\Temp\\second.exe",SW_SHOW); // Do some work here... }; ~MyClass() { Here I want to kill(Terminate) the second.exe } Any help plz ? Thankx } } Amarelia Maehsh Gujarat India
Amarelia wrote: But the problem is I don't know the Handle of the new exe that I have started using ShellExecute()... Why not? It's in the
PROCESS_INFORMATION
structure thatShellExecute()
populates.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
PostQuitMessage is another way. The tigress is here :-D
Not a good idea if handling other messages during shutdown is a concern. Call
PostMessage(WM_CLOSE)
instead.PostQuitMessage()
does not shut down an application properly as other messages might be initiated by the shutdown operation (e.g., save the document?) and those messages, along with any other messages that might be in the queue, will not be processed.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
Not a good idea if handling other messages during shutdown is a concern. Call
PostMessage(WM_CLOSE)
instead.PostQuitMessage()
does not shut down an application properly as other messages might be initiated by the shutdown operation (e.g., save the document?) and those messages, along with any other messages that might be in the queue, will not be processed.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Thank you David, that's well worth knowing. Elaine :rose: The tigress is here :-D
-
Amarelia wrote: But the problem is I don't know the Handle of the new exe that I have started using ShellExecute()... Why not? It's in the
PROCESS_INFORMATION
structure thatShellExecute()
populates.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Thank you very much I did the same but bit differently. I used CreateProcess() and in that there is last parameter as [out] parameter which is PROCESS_INFORMATION structure and I use that to close application. thankx once again Amarelia Maehsh Gujarat India
-
PostQuitMessage is another way. The tigress is here :-D
-
You could use CreateProcess() and TerminateProcess(), however TerminateProcess() ends a program so abruptly that some applications don't handle it well, it doesn't give them time to save their settings or other exit code. I'd recommend using FindWindowEx() and sending a WM_CLOSE to the main window.
-
Thank you very much I did the same but bit differently. I used CreateProcess() and in that there is last parameter as [out] parameter which is PROCESS_INFORMATION structure and I use that to close application. thankx once again Amarelia Maehsh Gujarat India
I'm glad you figured it out because my suggestion was wrong. I meant to say
CreateProcess()
notShellExecute()
.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb