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.