Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have process ID, so I want to check whether process is running or not.
Please help me...
Posted

I have solved this by below method
here I am passing processed this method will return true if id exist otherwise false. I have converted this method to VB and it's working fine.

C#
private bool ProcessExists(int id)
       {
           return Process.GetProcesses().Any(x => x.Id == id);
       }


Thanks,
-RG
 
Share this answer
 
Comments
FernMart 5-Oct-16 11:35am    
In VB

Private Function ProcessExists(id As Integer) As Boolean
Return Process.GetProcesses().Any(Function(x) x.Id = id)
End Function
Did you happen to look through Intellisense when you typed Process.?? There's a method in there called GetProcessById[^].
 
Share this answer
 
Comments
Ramug10 5-Mar-14 3:59am    
I have tried with this method but it's giving error like process with id 1506 not running currently.
Dave Kreskowiak 5-Mar-14 7:49am    
Well, it's either not running any more or you're looking on the wrong machine for the process ID.
VB
Dim pid As Process

            pid = Process.GetProcessById(1, "My-PC")
            If pid.Start = True Then
                MessageBox.Show("The Office Admin is already running!", "Warning !!!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2)
                e.Cancel = True
            End If
        End Sub
 
Share this answer
 
VB
Dim p() As Process
           p = Process.GetProcessesByName("Office Admin")

           If p.Length > 1 Then
               MessageBox.Show("The Office Admin is already running!", "Warning !!!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2)
               e.Cancel = True
           End If
 
Share this answer
 
Comments
Ramug10 4-Mar-14 8:12am    
Thanks for giving reply..
here you using process name but I need to check with process id.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900