Here is my problem: I need to close a process already running from a C # program. The problem is that the process now works like an icon (it comes down to the taskbar), and if the user does not open it at least once (which will never happen on machines without supervision), it will never have a main window.
Another requirement that I have is that the application is closed, not killed . I need it to write memory buffers to disk - and their destruction leads to data loss.
Here is what I have tried so far:
foreach (Process proc in Process.GetProcesses())
{
if (proc.ProcessName.ToLower().StartsWith("myapp"))
{
if (proc.MainWindowHandle.ToInt32() != 0)
{
proc.CloseMainWindow();
proc.Close();
}
}
}
if , MainWindowHandle == 0, . , . CloseMainWindow(), () . (), , , , .
, Win32 API:)