This Visual Basic .NET code will detect if multiple instances of the current application are running by retrieving the number of running processes with the same name.
- ‘If we find two or more running processes by the same name
If
Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
' Tell the user he can only have on instance running
MessageBox.Show("Only one instance of this program can be open at a given time", "Duplicate instance detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' Close the application
Application.Exit()
End If