0

I have 2 programs. I want to build an external tool, which prevents one of the programs from starting, when the other program is already running, and vice versa. I can't touch the code of either of the two programs.

I want to do it preferably with C#, but a scripting language will also be ok.

Can anyone help me with the concept how to implement it?

Thanks in advance.

casperOne
  • 73,706
  • 19
  • 184
  • 253
max12345
  • 29
  • 2
  • 9

2 Answers2

2

Write your tool as a windows service that keeps running in background and kills the second program if it starts. It can find out when a new process starts by listening to WMI events see .NET Events for Process executable start

Community
  • 1
  • 1
Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
2

There are couple of ways to do that. If you are using C# you should be getting the process name using the GetProcessesByName(). It would look something like this Process[] processes = Process.GetProcessesByName(processName); If you know the process name you can just kill the process Or else use the [Semaphore Class] (http://msdn.microsoft.com/en-us/library/system.threading.semaphore.aspx).

Ha Sh
  • 724
  • 5
  • 26