2

Example: Skype will be the application to trigger my service, if skype opens then my service should start. If skype closes then my service should close. Is that possible?

I want to put the status in my eventLog to check if it indeed works using something like this:

protected override void OnStart(string[] args)
    {
        galaxyeventLog.WriteEntry("Skype Start");
    }

    protected override void OnStop()
    {
        galaxyeventLog.WriteEntry("Skype Stop");
    }
Gaspa79
  • 5,488
  • 4
  • 40
  • 63
Sui Go
  • 463
  • 2
  • 12
  • 31

2 Answers2

2

Here is how you can do it

  1. You need to develop a SkypeMonitor service (a third service application). Its job is to track the Skype process. This can be done using WMI interface. Sample code can be found in

    .NET Process Monitor

  2. Using it you can hook into the start and stop skype process events to start / stop your service using the code below

    ServiceController controller = new ServiceController(serviceName); if (controller.Status==ServiceControllerStatus.Stopped) controller.Start();

Community
  • 1
  • 1
Cinchoo
  • 6,088
  • 2
  • 19
  • 34
1

The problem with easy solutions is that they will require the service to be already running.

What you could do, however, is disable all service behavior whenever you don't see skype on the list, and enable it when you actually see it.

In order to do this, you should periodically check the open processes using:

Process[] processlist = Process.GetProcesses();

of the System.Diagnostics; namespace.

Hope this helps =)

Gaspa79
  • 5,488
  • 4
  • 40
  • 63