I am writing a C# application and before I exit, I need to close another console application based on its window title... this second application (staticEngineWriter) is a C program that uses SetConsoleTitle() function to set its title.
The code I have in C# to do this is below. The problem is it is returning the process name instead of the window title of the C application. Seems simple enough but I wonder if it has to do with how the writer application is setting its title using the SetConsoleTitle function.
static void stopWriter()
{
Process[] proc = Process.GetProcessesByName("staticEngineWriter");
foreach (System.Diagnostics.Process CurrentProcess in proc)
{
Console.Writeline(CurrentProcess.MainWindowTitle); //debug
if (CurrentProcess.MainWindowTitle.Contains("My Writer"))
{
CurrentProcess.Kill();
}
}
}