You're going to want to use a user32.dll function.
Declare the function like so:
Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Using the API is easy. Here's an example snippet.
<System.Runtime.InteropServices.DllImport("user32.dll")>
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)>
Private Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal flags As ShowWindowEnum) As Boolean
End Function
<System.Runtime.InteropServices.DllImport("user32.dll")>
Private Shared Function SetForegroundWindow(ByVal hwnd As IntPtr) As Integer
End Function
Private Enum ShowWindowEnum
Hide = 0
ShowNormal = 1
ShowMinimized = 2
ShowMaximized = 3
Maximize = 3
ShowNormalNoActivate = 4
Show = 5
Minimize = 6
ShowMinNoActivate = 7
ShowNoActivate = 8
Restore = 9
ShowDefault = 10
ForceMinimized = 11
End Enum
Public Sub BringMainWindowToFront(ByVal processName As String)
Dim bProcess As Process = Process.GetProcessesByName(processName).FirstOrDefault()
If bProcess IsNot Nothing Then
If bProcess.MainWindowHandle = IntPtr.Zero Then
ShowWindow(bProcess.Handle, ShowWindowEnum.Restore)
End If
SetForegroundWindow(bProcess.MainWindowHandle)
Else
Process.Start(processName)
End If
End Sub
You can modify
BringMainWindowToFront to your own needs (like using PID).
Hope this helps!