vb.net - Check process is running, then switch to it? -


i have below code check if 'chrome' running when click button1. if not launches chrome. works dont know code needed in if statement switch chrome if running. simple missing.

private sub button1_click(sender object, e eventargs) handles button1.click      if process.getprocessesbyname("chrome").count > 0         ??**show running application**??      else         process.start("c:\program files\google\chrome\application\chrome.exe")     end if   end sub 

as mentioned in above comment, chrome starts many instances of itself. each tab has own process, how going tell 1 switch to?. come's down tab selected when minimize window or minimizes task bar. below should out , it's tried , tested. issue is, if open chrome , have multiple tabs it's fine, if create instance of chrome not show second instance, bring forward first instance... if close first instance, second instance of course come forward.

public class form1  #region "dll imports"     <system.runtime.interopservices.dllimport("user32.dll")> _     private shared function setforegroundwindow(handle intptr) boolean     end function      <system.runtime.interopservices.dllimport("user32.dll")> _     private shared function showwindow(handle intptr, ncmdshow integer) boolean     end function      <system.runtime.interopservices.dllimport("user32.dll")> _     private shared function isiconic(handle intptr) boolean     end function #end region      private sub button1_click(sender object, e eventargs) handles button1.click        startorshowprocess("chrome")     end sub       private sub startorshowprocess(byval strprocessname string)         try             dim handle intptr             dim proc process() = process.getprocessesbyname(strprocessname)             if proc.count > 0                 each procp process in proc                     handle = procp.mainwindowhandle                     if handle <> 0 andalso isiconic(handle) 'do have handle , minimized?                         showwindow(handle, 9)                         setforegroundwindow(handle)                     end if                 next             else 'not running or started...                 process.start(strprocessname)             end if          catch ex exception             'handle error...         end try     end sub   end class 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -