Robert Samuel White wrote:
Do you happen to know how to check for a running application? And if
it is not running, to execute it? I'm not sure where to start.
Basically, the front-end applications need to check to see if the
tray program is even running. If it's not, then it needs to open it
up. From there, the tray program forces the user to log in before
the front-end applications may be accessed.
There are typically three ways in which an application can check if an
instance of itself or another application is already running. One is
enumerating all windows looking for one with a specific title (for a tray
app this window would typically be invisible). One is checking the list of
running process to see if the executable is running. The last one is using
named pipes. The application that needs to be checked typically creates a
named pipe, and the application that does the checking tries to connect to
it. If that works, the application is running.
Unfortunately, only the last one is a truly robust method, and as it
requires pipes so it can't be done in pure .Net. The behaviour however can
be emulated using .Net Remoting. Simply have the tray app be a host
application, have it listen on some port with some URI (see the link I
provided with info on how to do all this, it contains a very simple example
of a host and client app), then have the other application be a client, and
attempt to connect to the remoting channel on the localhost. If that fails,
the tray app is not running, so you must launch it using CreateProcess.
For all the communication the other way around, the tray app is the remoting
client to the other applications, which act as host in that scenario.
I suggest you read the documentation on .Net Remoting thoroughly.
--
Sven Groot
http://unforgiven.bloghorn.com