Try to send Control-C event to application console.
Try to attach to the application's console and send a Control-C event when
shutting down. If a console exists, is successfully attached and successfully
sent the event, allow a grace period for the application to exit before sending
window messages or eventually calling TerminateProcess().
Now console applications which register shutdown handlers, such as java
launched from a batch file, have a chance to clean up and shut down gracefully.
Thanks Eric Cheldelin.