If this is a GUI application. It can also respond to Alt + F4 via SendKeys.
Unlike ctrl + x, Alt + F4 does not depend on which window has focus. This is the standard accelerator for Windows applications, and most older graphics applications will support it. The main reason SendKey is considered flakey is because keystrokes fall into the focus window, which may or may not understand them. But Alt + F4 is an accelerator, so it should work no matter which window has focus.
If you can get the handle to the main window. (use FindWindow if you don't already have one). You can
PostMessage(hwndApp, WM_SYSCOMMAND, SC_CLOSE, 0);
This is equivalent to selecting the close option from the system menu in the window. SendMessage should also work, but PostMessage is more secure, since your application does not wait for the message to be delivered.
WM_SYSCOMMAND
source share