[RESOLVED] Check if a Process is Running or not
hi all,
I am trying to check if a process is running, if yes it should fire a messagebox saying it is or it isnt, i am using this code by Rohit Arora from this post
http://social.msdn.microsoft.com/For...f-fb9faed7f330
It fires the messagebox when process is running but not when the process is not running, can anyone please help me out here?
vb.net Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
IsApplicationRunning("iexplore")
End Sub
Private Sub IsApplicationRunning(ByVal ApplicationName As String)
'http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/abb28d8c-c432-4be1-9b4f-fb9faed7f330
Dim Currentprocess() As Process = Process.GetProcessesByName(ApplicationName)
If Currentprocess.Length > 0 Then
For Each RunningProcess As Process In Currentprocess
If RunningProcess.ProcessName = ApplicationName Then
MessageBox.Show(ApplicationName & " is already running")
End If
Next
End If
If Currentprocess.Length > 0 Then
For Each RunningProcess As Process In Currentprocess
If Not RunningProcess.ProcessName = ApplicationName Then
MessageBox.Show(ApplicationName & " is not running")
End If
Next
End If
End Sub
Re: Check if a Process is Running or not
Code:
Private Sub IsApplicationRunning(ByVal ApplicationName As String)
'http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/abb28d8c-c432-4be1-9b4f-fb9faed7f330
Dim Currentprocess() As Process = Process.GetProcessesByName(ApplicationName)
If Currentprocess.Length > 0 Then
For Each RunningProcess As Process In Currentprocess
If RunningProcess.ProcessName = ApplicationName Then
MessageBox.Show(ApplicationName & " is already running")
End If
Next
Else
MessageBox.Show(ApplicationName & " is not running")
End If
End Sub
Re: [RESOLVED] Check if a Process is Running or not
Hey, while we're reducing code, let's go all the way!
Private Sub IsApplicationRunning(ByVal ApplicationName As String)
If Process.GetProcessesByName(ApplicationName).Length > 0
MessageBox.Show(ApplicationName & " is already running")
Else
MessageBox.Show(ApplicationName & " is not running")
End If
End Sub