Results 1 to 3 of 3

Thread: [RESOLVED] Check if a Process is Running or not

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Resolved [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:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         IsApplicationRunning("iexplore")
    3.     End Sub
    4.  
    5.     Private Sub IsApplicationRunning(ByVal ApplicationName As String)
    6.         'http://social.msdn.microsoft.com/Forums/et-EE/netfxbcl/thread/abb28d8c-c432-4be1-9b4f-fb9faed7f330
    7.         Dim Currentprocess() As Process = Process.GetProcessesByName(ApplicationName)
    8.         If Currentprocess.Length > 0 Then
    9.             For Each RunningProcess As Process In Currentprocess
    10.                 If RunningProcess.ProcessName = ApplicationName Then
    11.                     MessageBox.Show(ApplicationName & " is already running")
    12.                 End If
    13.             Next
    14.         End If
    15.         If Currentprocess.Length > 0 Then
    16.             For Each RunningProcess As Process In Currentprocess
    17.                 If Not RunningProcess.ProcessName = ApplicationName Then
    18.                     MessageBox.Show(ApplicationName & " is not running")
    19.                 End If
    20.             Next
    21.         End If
    22.     End Sub

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    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

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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
  •  



Click Here to Expand Forum to Full Width