473,320 Members | 1,939 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,320 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 1728
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?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.