By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Checking whether a process is in execution

P: n/a
kd
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.
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

"kd" <kd@discussions.microsoft.com> wrote in message
news:kd@discussions.microsoft.com:
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.


Nov 21 '05 #2

P: n/a
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

"kd" <kd@discussions.microsoft.com> wrote in message
news:kd@discussions.microsoft.com:
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.


Nov 21 '05 #3

P: n/a
kd
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

"Brian Swanson" wrote:
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

"kd" <kd@discussions.microsoft.com> wrote in message
news:kd@discussions.microsoft.com:
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.


Nov 21 '05 #4

P: n/a
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.GetCurrentProce ss.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
"kd" wrote:
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

"Brian Swanson" wrote:
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

"kd" <kd@discussions.microsoft.com> wrote in message
news:kd@discussions.microsoft.com:
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.


Nov 21 '05 #5

P: n/a
kd
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

"BrianDH" wrote:
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.GetCurrentProce ss.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
"kd" wrote:
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

"Brian Swanson" wrote:
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

"kd" <kd@discussions.microsoft.com> wrote in message
news:kd@discussions.microsoft.com:
> 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.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.