Detect multiple instances of the application

  1. 'If we find two or more running processes by the same name
  2. If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
  3.     ' Tell the user he can only have on instance running
  4.     MessageBox.Show("Only one instance of this program can be open at a given time", "Duplicate instance detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  5.     ' Close the application
  6.     Application.Exit()
  7. End If


Written by