Saturday, July 28, 2012

How to Check whether the application/process is running or not by passing the process name

Here is the awesome VB.Net code to check whether the application/process is running or not by passing the process name:

  1. Module modMain  
  2.   Sub Main()  
  3.     'Check whether acrobat is running or not  
  4.     If IsProcessRunning("acrobat"Then  
  5.       Console.WriteLine("Yes. Acrobat is running")  
  6.     Else  
  7.       Console.WriteLine("No. Acrobat is not running")  
  8.     End If  
  9.   End Sub  
  10.   Private Function IsProcessRunning(ByVal sProcess As StringAs Boolean  
  11.     For Each oProc As Process In Process.GetProcessesByName(sProcess)  
  12.       Return True  
  13.     Next  
  14.   End Function  
  15. End Module 

No comments:

Post a Comment