views:

43

answers:

2

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.

+2  A: 

You could use pipes to send them messages.

Matthew Ferreira
+2  A: 

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.

Hans Passant
I can do that, although I was looking for a way to send a close message. The apps have a message loop, I just can't figure out a way to get a message into it since there's no main window.
jackjumper
Thanks for the suggestion, however
jackjumper