How can I set focus on other application based on process name in VB2010?
What I can do now is set focus on other application based on windows name using FindWindow then use SetForegroundWindow. Below is what I currently have
Dim theHandle As IntPtr
theHandle = FindWindow(Nothing, "Gmail: Email from Google")
If theHandle <> IntPtr.Zero Then
You can use
System.Diagnostics.Process to look up a process by name and then find the window title:
For Each app As Process In Process.GetProcessesByName("firefox") Dim theHandle As IntPtr = FindWindow(Nothing, app.MainWindowTitle) If theHandle <> IntPtr.Zero Then SetForegroundWindow(theHandle) End If Next
Use the static
GetProcessesByName method and then the
MainWindowTitle property. For this sample you would need
Import System.Diagnostics to import the right namespace.