|
-
Jan 19th, 2013, 02:05 AM
#1
Thread Starter
Frenzied Member
[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
-
Jan 19th, 2013, 02:29 AM
#2
Hyperactive Member
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
-
Jan 19th, 2013, 12:55 PM
#3
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
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|