none
Problem Detecting Application Process RRS feed

  • Question

  • Hi everyone, I am trying to make an application that is supposed to make sure another necessary application is running on startup, and as long as the application is running, it should load some files into C:\(which I will do later), and if it is not running, pop up another form.

    I have two forms for this, FormLoad and Form1, the startup window is FormLoad, and I put these codes in it.

            Dim P4DProcess As Process
            For Each P4DProcess In Process.GetProcesses
                If P4DProcess.ProcessName = "Prepar3D" Then
                    MessageBox.Show("P3D")
                Else
                    Me.Hide()
                    Form1.Show()
                End If
            Next


    Prepar3D.exe is the file that I want the application to confirm running. I tried to make a messagebox pop up if Prepar3D.exe is running, and it worked correctly. However, Form1 always show at the first second on startup, although I set the startup window to FormLoad, and another weird thing is even if Prepar3D.exe is not running, FormLoad won't disappear. Is there an error in my codes, or should I change anything in my settings? THX

    Sunday, February 17, 2019 9:05 AM

Answers

  • Try this:

    Dim found as Boolean = False

    For Each P4DProcess In Process.GetProcesses

       If P4DProcess.ProcessName = "Prepar3D" Then

          Found = True

          Exit For

       End If

    Next       

    If Found Then

       MessageBox.Show("P3D")

    Else

       Me.Hide()

       Form1.Show()

    End If

    Sunday, February 17, 2019 10:15 AM

All replies

  • Try this:

    Dim found as Boolean = False

    For Each P4DProcess In Process.GetProcesses

       If P4DProcess.ProcessName = "Prepar3D" Then

          Found = True

          Exit For

       End If

    Next       

    If Found Then

       MessageBox.Show("P3D")

    Else

       Me.Hide()

       Form1.Show()

    End If

    Sunday, February 17, 2019 10:15 AM
  • Thanks, worked smoothly!
    Sunday, February 17, 2019 6:28 PM