473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Checking whether a process is in execution

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
5 1733
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Deepak Sarda | last post by:
Hello everyone. I have run into something which I believe is a bug or a shortcoming of the threading.Thread module. My program spawns 15 threads. For this I've creating a new class with...
0
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to...
15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
10
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another...
0
by: kd | last post by:
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...
28
by: romy | last post by:
What's the easiest way to verify the user had entered a valid date ?
7
by: Hulo | last post by:
In a C program I am required to enter three numbers (integers) e.g. 256 7 5 on execution of the program. C:\> 256 7 5 There should be spaces between the three numbers and on pressing "enter",...
7
by: pradeep_TP | last post by:
hello all, I want to know how can I check whether a web site us running or not. I have used HttpWebRequest but when I give a web site address, It takes few number of seconds to throw exception...
10
by: frakie | last post by:
Hi 'body, is there a method to check if a pointer is pointing a freed memory location?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.