Click here to Skip to main content
15,889,527 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Setting focus on another application using Process name

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
29 Jul 2011CPOL 57.7K   4   4
How to set focus on another application using the process name

VB.NET code:


VB
If Process.GetProcessByName("ExternalApplication").Length >=1 Then
     For Each ObjProcess As Process In Process.GetProcessByName("ExternalApplication")
          AppActivate(ObjProcess.Id)
          SendKeys.SendWait("~")    
     Next
End If

The SendKeys coding is used to maximize the external application when it's minimized. See this link to see more SendKeys commands: http://www.developerfusion.com/article/57/sendkeys-command/[^].

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer Mahindra Logisoft Business Solution Limited, Chenn
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionProblem in code Pin
ChrisRaisin19-Feb-22 14:43
ChrisRaisin19-Feb-22 14:43 
GeneralMy vote of 1 Pin
Clinton McCool17-Jul-18 10:24
Clinton McCool17-Jul-18 10:24 
GeneralMy vote of 5 Pin
TheCrazyTim7-May-13 17:26
TheCrazyTim7-May-13 17:26 
GeneralIs there a better way to do it? without the Sendkeys command? Pin
noobiam25-Mar-13 21:16
noobiam25-Mar-13 21:16 
I tried to do something similar:

*appPid var conatins the PID of the app.
VB
AppActivate(appPid) ' activated but not focused
SendKeys.Send("%{TAB}") ' switch back to Me
SendKeys.Send("%{TAB}") ' switch to show the program

this code (if it would work as it meant to on my PC at least) should set focus to app by its PID for example and then do Alt+Tab to get be to the calling form and then do Alt+Tab again to fully show the needed app.
but its not work on my PC and do a lot of bad things (PC freeze) :\

Can someone please show another way to do it? I am sure there should be good clean way to show another window :\

Thanks.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.