Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Show an already running process

  1. #1

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Resolved [RESOLVED] [2005] Show an already running process

    Howdy all,
    Here's an example of what I'm trying to do. If my process has not started, then start it. If my process has started, then bring the currently running process to the front instead of opening another instance of it. For example
    vb.net Code:
    1. Private p As Process = Nothing
    2.  
    3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.     If p Is Nothing OrElse p.HasExited Then
    5.         p = New Process()
    6.         p.StartInfo.FileName = "c:\test.txt"
    7.         p.Start()
    8.     Else
    9.         ' This process is already running so
    10.         ' bring is to the front/maximize it
    11.         ' instead of opening another one.
    12.     End If
    13. End Sub

    I've waded through the Process class but have not found what I'm looking for. How can I, if in the example above, I already have an instance of NotePad open, bring it to the front instead of opening another instance?

    Am I smelling API of some sort? Sorry if this turns out to be the inappropriate forum. Thanks.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Show an already running process

    No API needed...
    Code:
        Private p As Process = Nothing
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If p Is Nothing OrElse p.HasExited Then
                p = New Process()
                p.StartInfo.FileName = "c:\test.txt"
                p.Start()
            Else
                ' This process is already running so
                ' bring is to the front/maximize it
                ' instead of opening another one.
                AppActivate(p.Id)
            End If
        End Sub

  3. #3

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Show an already running process

    Perfect. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width