Checking whether a process is in execution

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

If the name of a process is known, is it possible to check whether it is in
execution?

What I did was to fetch all the processes running on the system using
Process.GetProcesses() and traverse through the array looking for the Process
name.

Is there a shortcut or easier way to accomplish this?

Thanks.

kd.
 
I personally use this routine to check for a previous instance on an
app.

Function PrevInstance() As Boolean
If UBound( _
Diagnostics.Process.GetProcessesByName( _
Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function

Hope this helps,
Brian Swanson
 
Thanks Brian.

But, I am not looking for a previous instance of an application. I am
looking for another application exe whose name I know. So, I using
GetCurrentProcess.ProcessName won't help.

Regards
ks
 
2 Examples:
'Check to see if another copy of your program is running
Public Sub CheckForExistingInstance()
'Get number of processes of you program
If
Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1
Then
MessageBox.Show("Another Instance of this process is already running",
"Multiple Instances Forbidden", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Application.Exit()
End If
End Sub
'Check to see if “ProgramNane†is running
Public Sub CheckForWinfax()
Try
Dim myProcesses() As Process
myProcesses = Process.GetProcessesByName("programname.exe")
If (myProcesses.Length = 1) Then
Else
Application.Exit()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Checking For WinFax !")
End Try
End Sub
 
Thanks BrianDH for your response.

Here's a sample of my code; The message "Not running" is shown, even though
Test.exe is running.

Dim TestProcess() As Process
Try
TestProcess= Process.GetProcessesByName("Test.exe")
If TestProcess.Length = 0 Then
MsgBox("Not running", MsgBoxStyle.OKOnly)
Else
MsgBox("Running", MsgBoxStyle.OKOnly)
End If
Catch ex As Exception
MsgBox("Error!")
End Try

Do you have any suggestions?

Thanks.
kd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top