title: Preventing multiple process instances of a single executable
body: <p>I am using .NET with C#.</p>
  
  <p>I want to prevent two instances of the same executable to run at the same time, but I don't want to prevent the same process that is run from another folder.</p>
  
  <p>For example, I have an executable that is in two different locations:</p>
  
  <ul>
  <li><p>C:\MyProject\Master\Program.exe</p></li>
  <li><p>C:\MyProject\Slave\Program.exe</p></li>
  </ul>
  
  <p>These are the same .exe files, but in two different locations.</p>
  
  <p>I want to allow one instance of Program.exe that is run from Master folder and one instance from the Slave folder, but no two of any. </p>
  
  <p>I've tried to do this by checking the number of processes that have the same name (Process.GetProcessesByName), but then I can't differ the two.</p>
  
  <p>The closest I have found is to get the Modules from the Process.</p>
  
  <p>The first one in the list is ProcessModule of the exe. But I am not sure if this will always be the first one on the list. Is there any guarantee for that, or is there a better solution to the explained problem?</p>