Running Applications?

Morning everyone, I've posted this question before but haven't started actually coding this until now so I need to know a little bit of information. Basicly I want to determine if an application is already running. My program works with another one to output data and I would like to  automatically detect if that other application is running. The code I'm using is

Dim p() As Process = Process.GetProcessesByName("NameOfProcess")

What I can't figure out is how do I do for example use an if statement with it

If this process is running than do this

Also if anyone can help me with what does the code above actually output I've tried to display P() through a msgbox and it does nothing always gives me an index out of bounds error and I've tried it with running processes and non running ones, and I've tried it with a number of different index's.


Any help would be greatly appreciated. Thanks in advance.



Answer this question

Running Applications?

  • Mikepy

    The code outputs an array of processes with the given name>

    Dim NameOfProcess As String = "Notepad"

    Dim p() As Process = Process.GetProcessesByName(NameOfProcess)

    If p.Length > 0 Then

    MessageBox.Show(p.Length & " Process(s) Named " & NameOfProcess & " are running!")

    p(0).Kill() 'this kills the first process in the array of processes

    End If



  • Running Applications?