Preventing multiple process instances for a single executable

I am using .NET with C #.

I want both instances of the same executable to be executed at the same time, but I do not want to interfere with the same process that starts from another folder.

For example, I have an executable file that is in two different places:

  • C: \ MyProject \ Master \ program.exe

  • C: \ MyProject \ slave trade \ program.exe

These are the same .exe files, but in two different places.

I want to allow one instance of Program.exe that starts from the main folder and one instance from the Slave folder, but not one of the two.

I tried to do this by checking the number of processes with the same name (Process.GetProcessesByName), but then I can not distinguish between them.

The closest I found is to get the modules from the process.

- ProcessModule exe. , . - , ?

+3
2

- , , - :

Process[] processes = Process.GetProcessesByName("Program");

.

:

string fullPath = process.MainModule.FileName;

, , .

+1

, . , .

. : Mutex

+1

All Articles