Replace StartorShowProcesses with the following -
Private Sub BringToTop(name As String)
Try
Dim procs() As Process = Process.GetProcessesByName(name)
Dim thisproc As Process = Process.GetCurrentProcess()
Dim sess = thisproc.SessionId
For Each proc In procs
If proc.SessionId = sess Then
Dim handle As IntPtr = proc.MainWindowHandle
If handle <> IntPtr.Zero Then
If SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE) = False Then
Throw New Win32Exception(Marshal.GetLastWin32Error())
End If
End If
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
You'll also need to include this -
<DllImport("User32.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall, SetLastError:=True)>
Private Shared Function SetWindowPos(hwnd As IntPtr,
hwndAfter As IntPtr,
X As Integer,
Y As Integer,
cx As Integer,
cy As Integer,
flags As UInteger) As Boolean
End Function
Dim SWP_NOSIZE As UInteger = &H1
Dim SWP_NOMOVE As UInteger = &H2
Dim SWP_NOZORDER As UInteger = &H4
Dim SWP_NOREDRAW As UInteger = &H8
Dim SWP_NOACTIVATE As UInteger = &H10
Dim SWP_FRAMECHANGED As UInteger = &H20 'The frame changed: send WM_NCCALCSIZE
Dim SWP_SHOWWINDOW As UInteger = &H40
Dim SWP_HIDEWINDOW As UInteger = &H80
Dim SWP_NOCOPYBITS As UInteger = &H100
Dim SWP_NOOWNERZORDER As UInteger = &H200 'Don't do owner Z ordering
Dim SWP_NOSENDCHANGING As UInteger = &H400 '/Don't send WM_WINDOWPOSCHANGING
Dim SWP_DRAWFRAME As UInteger = SWP_FRAMECHANGED
Dim SWP_NOREPOSITION As UInteger = SWP_NOOWNERZORDER
Dim SWP_DEFERERASE As UInteger = &H2000
Dim SWP_ASYNCWINDOWPOS As UInteger = &H4000
Dim HWND_TOP As IntPtr = 0
Dim HWND_BOTTOM As IntPtr = 1
Dim HWND_TOPMOST As IntPtr = -1
Dim HWND_NOTOPMOST As IntPtr = -2
and
Imports System.ComponentModel