Private Function IsAlreadyRunningInstance() As Boolean
Dim current As process = System.Diagnostics.Process.GetCurrentProcess()
Dim processes As process() = System.Diagnostics.Process.GetProcessesByName(current.ProcessName)
'Loop through the running processes in with the same name
Dim process As process
For Each process In processes
'Ignore the current process
If process.Id <> current.Id Then
'Make sure that the process is running from the exe file.
If [Assembly].GetExecutingAssembly().Location.Replace("/", "/") = current.MainModule.FileName Then
'Return true.
Return True
End If
End If
Next process
'No other instance was found, return false.
Return False
End Function