473,385 Members | 1,582 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.

Detecting that a program is already running

Hi
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already
running? I know I could do this with a dummy file by putting something in the
file while it's running and emptying the file when it's not running, but I was
hoping for something a little more professional. Has anyone done this yet?

Joe
Nov 21 '05 #1
7 1230
* jo***@aol.com (Joecx) scripsit:
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already
running?


<URL:http://www.pobox.com/~skeet/csharp/faq/#one.application.instance>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length >
0 Then
' exit application or display message
End If
-- Code ends --

Hope this helps.

"Joecx" <jo***@aol.com> wrote in message
news:20***************************@mb-m21.aol.com...
Hi
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already running? I know I could do this with a dummy file by putting something in the file while it's running and emptying the file when it's not running, but I was hoping for something a little more professional. Has anyone done this yet?
Joe

Nov 21 '05 #3
Herfried

For you to change

http://www.yoda.arachsys.com/csharp/...ation.instance
:-)

Cor
Nov 21 '05 #4
* "Cor Ligthert" <no**********@planet.nl> scripsit:
For you to change

http://www.yoda.arachsys.com/csharp/...ation.instance


This one works too, and I think it's the preferred one. Thanks for
making me aware of that.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
* "Matt S" <ma**@toomuchspamalready.com> scripsit:
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length >
0 Then
' exit application or display message
End If


Notice that the application name isn't necessarily unique.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6
Good point. Noted.

Matt.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uC*************@TK2MSFTNGP10.phx.gbl...
* "Matt S" <ma**@toomuchspamalready.com> scripsit:
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length > 0 Then
' exit application or display message
End If


Notice that the application name isn't necessarily unique.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length
> 0 Then

' exit application or display message
End If
-- Code ends --


Note that this code will detect it self. It should stand .Length > 1.
BTW ProcessName is not necessary unique.

--
Pozdrav,
Josip Medved, MCSD
http://www.jmedved.com
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Woojay Jeon | last post by:
OK, I tried a Google search on this Usenet group but couldn't find a solution, so I'm posting my question here (if there's a better archive than the one in Google, please let me know). Does...
6
by: Juho Saarikko | last post by:
The program attached to this message makes the Python interpreter segfault randomly. I have tried both Python 2.2 which came with Debian Stable, and self-compiled Python 2.3.3 (newest I could find...
6
by: Pierre-Yves | last post by:
Hello, I would like to prevent my perl program to be executed several times simultaneously (if the program is already running, I would like to display a message like "another instance of this...
22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
7
by: Joecx | last post by:
Hi Does anyone have the code or maybe give me a start on how to detect if my program is already running if someone tries to run it again while it's already running? I know I could do this with a...
3
by: RM Powell | last post by:
OK, this is probably a dumb, newbie quesiton. But I've searched quite a bit on this group and in the "help" files and haven't been able to find the answer. I run a crisis program for kids and...
7
by: fox | last post by:
Maybe this is not the best group to ask this question, but I don't know a better one. I'm looking for a *portable* program in C (I mean source code) to detect whether unaligned word access is:...
2
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents...
1
by: Fred Morrison | last post by:
In VB6, I would check to see if Excel was already running by this technique Private m_booExcelCreatedHere As Boolean Dim xlApp as Excel.Application On Error Resume Next ' temporarily...
2
AaronL
by: AaronL | last post by:
Hello, Is there an API I can use to detect windows processes? For example, if I were to run notepad.exe, and I wanted to pop a message up in my program that said "notepad.exe" is running? How...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.