Hi, I am trying to write a C code on windows to send cntrol C signal to a running, so that the running application closes gracefully. Here is the code I have tried to write: Code: #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include <windows.h> void main() { int i=0; HWND h = NULL; h = FindWindow(NULL,"RUNNING EXE"); printf("[%d]\n",h); i = SendMessage(h,WM_CHAR,0x03,0); printf("[%d]\n",i); } But the running application is not closing gracefully, it is simply receiving ^C. This is not solving my purpose. Waiting for a quick response. Regards.
Ctrl-C doesn't kill Windows programs. You could try using TaskKill instead http://technet.microsoft.com/en-us/library/bb491009.aspx Or if you want to do it programmatically you could try sending WM_CLOSE to the main window, but the behaviour will depend on what the application does with that message.
Hi thanks for da reply. But the second application closes gracefully only if it receives SIGINT signal(Generated by cntrol C). Taskkill will forceully kill the application without gracefully closing it. Please guide something related to this.