Closing a Task Tray app

I have a set of server apps that run in the task tray. I'm trying to write a little server management app in c# that can gracefully close the applications. However I'm having trouble figuring out how to do it.

I can get the process (an instance of the Process class). Calling Process.CloseMainWindow() doesn't work. You don't get a Process.MainWindowHandle for a task tray process (it's zero, and is documented that this is the case), so I can't send, say, a WM_SYSCOMMAND, SC_CLOSE message.

I can Kill() it, but that's not graceful. Any ideas? The server apps are written in Delphi Win32. I can modify them.

Answers


You could use pipes to send them messages.


You could iterate the windows with EnumWindows to find the hidden window that is associated with the tray icon. That's all rather fugly and error prone. Do this cleanly, have these 'server apps' create a named pipe. You can connect to them in your manager app by using the well-known name and then send them a command. System.IO.Pipes namespace.


Need Your Help

Why to use # in embedded code asp.net

asp.net

when to use # used inside <% %> ?

Java URLConnection error with ntlm authentication, but only on Linux and only Java 7

java authentication ntlm urlconnection

I am trying to open an http connection to an url protected with the NTLM authentication scheme. This code has been working correctly for 2 year when we were on Java 6.I wrote a small java program w...