473,395 Members | 1,464 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,395 software developers and data experts.

Prevent starting up twice

Hello,

Can anyone tell me what the best way is to prevent an application from
starting up twice.

Thanks,
Dirk


Jul 22 '05 #1
8 2745
"Dirk" <so*****@nomail.xx> wrote in message
news:Gq********************@casema.nl...
Hello,

Can anyone tell me what the best way is to prevent an application from
starting up twice.


This is off-topic in this group, as standard C++ defines no such mechanism.
It usually involves things such as creating named pipes and checking if that
pipe exists or not, stuff like that, but it is usually far from trivial and
highly platform specific.

Ask again in a newsgroup for your specific OS.

--
Unforgiven

Jul 22 '05 #2
Dirk wrote:
Can anyone tell me what the best way is to prevent an application from
starting up twice.


You cannot prevent it from starting up twice if your OS allows that.
However, you can try to avoid letting your application proceed far
beyond the startup code if you can determine that another copy of your
application is already running. The only standard C++ way I know is
to check if there exists a file in a predetermined location and when
the application starts, and if it does, exit, and if it doesn't, create
one to indicate that your application is the first one. The application
that creates the file shouldn't forget to delete it when it closes.

If you want something that doesn't involve creating files, you need
a platform-specific solution. Ask in a newsgroup dedicated to your
platform.

Victor
Jul 22 '05 #3
Victor Bazarov posted:
Dirk wrote:
Can anyone tell me what the best way is to prevent an application from starting up twice.
You cannot prevent it from starting up twice if your OS

allows that. However, you can try to avoid letting your application proceed far beyond the startup code if you can determine that another copy of your application is already running. The only standard C++ way I know is to check if there exists a file in a predetermined location and when the application starts, and if it does, exit, and if it doesn't, create one to indicate that your application is the first one. The application that creates the file shouldn't forget to delete it when it closes.
If you want something that doesn't involve creating files, you need a platform-specific solution. Ask in a newsgroup dedicated to your platform.

Victor


For Windows:

go to msdn.microsoft.com and look up "CreateMutex".
-JKop
Jul 22 '05 #4
On Mon, 20 Sep 2004 14:28:23 +0200, "Dirk" <so*****@nomail.xx> wrote:
Can anyone tell me what the best way is to prevent an application from
starting up twice.


If you're using Windows, here's the code generated by VC++ to prevent
a second instance of an application named WWB:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if (hPrevInstance)
{
MessageBox(0,"WWB is already running",NULL,MB_OK);
return FALSE; // previous instance not allowed
}

Jul 22 '05 #5

"Terry Liittschwager" <te***@epud.net> wrote in message
news:5l********************************@4ax.com...
On Mon, 20 Sep 2004 14:28:23 +0200, "Dirk" <so*****@nomail.xx> wrote:
Can anyone tell me what the best way is to prevent an application from
starting up twice.


If you're using Windows, here's the code generated by VC++ to prevent
a second instance of an application named WWB:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if (hPrevInstance)
{
MessageBox(0,"WWB is already running",NULL,MB_OK);
return FALSE; // previous instance not allowed
}


This gives an example of why it's not a good idea to
ask or answer off topic questions. This off topic
answer is incorrect. See a Windows newsgroup and/or
MSDN for further information.

-Mike

Jul 22 '05 #6
Mike Wahler wrote:
"Terry Liittschwager" <te***@epud.net> wrote in message
news:5l********************************@4ax.com...
On Mon, 20 Sep 2004 14:28:23 +0200, "Dirk" <so*****@nomail.xx> wrote:
Can anyone tell me what the best way is to prevent an application from
starting up twice.


If you're using Windows, here's the code generated by VC++ to prevent
a second instance of an application named WWB:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if (hPrevInstance)
{
MessageBox(0,"WWB is already running",NULL,MB_OK);
return FALSE; // previous instance not allowed
}

This gives an example of why it's not a good idea to
ask or answer off topic questions. This off topic
answer is incorrect. See a Windows newsgroup and/or
MSDN for further information.


Well, since we're all indulging on OTness - the posted answer is correct
for 16-bit Windows (i.e. pre-Win95), but not Win32. ;-P

--
Mike Smith
Jul 22 '05 #7

"Dirk" <so*****@nomail.xx> wrote in message news:Gq********************@casema.nl...
Hello,

Can anyone tell me what the best way is to prevent an application from
starting up twice.


Fix it so that it doesn't start up once.

Jul 22 '05 #8
Dirk wrote:

Hello,

Can anyone tell me what the best way is to prevent an application from
starting up twice.


When the app starts, open a predefined (temporary) file in exclusive mode*. If
it succeeds, continue; if it fails, terminate. Close the file when exiting.

*Presumes that your OS and C/C++ library supports exclusive file access.

Other than that, you will need to resort to more OS specific solutions -- find
a newsgroup that discusses your OS and post the question there.
Jul 22 '05 #9

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

Similar topics

3
by: entoone | last post by:
I have an html form, that has fields and when the submit button is pressed, the information is transferred to a php file. Which then inserts the data into my sql database. How can I go about...
2
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely...
7
by: Douglas | last post by:
I have a frontend and backend database , program.mde and data.mdb on a client PC. How do i prevent them launching the program.mde more than once on a single PC? Somtimes they minizmise the program...
5
by: R. Ian Lee | last post by:
I have an ASP.NET page that spawns a popup window using javascript's window.open. This works fine. It pops up, you enter some data, press save and everything saves as it should. But, if you...
24
by: Charles Law | last post by:
When I click a button I don't want the click event to fire. Is this possible? In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent...
7
by: e_matthes | last post by:
Hello everyone, I've read enough about email validation to know that the only real validation is having a user respond to a confirmation message you've sent them. However, I want to store the...
0
by: josephkorn | last post by:
Hi all. I have a problem in my website in trying to prevent a user from double submitting the form. I am calling a subroutine from my page_load event that passes in the commandbutton that I want...
6
by: Arthur Dent | last post by:
Anyone know, in VB.NET (2005) how to prevent duplicate occurrences of the same event handler on an event? e.g... I have some object which raises an event, and some other class which consumes...
0
by: lotus111 | last post by:
I am using the new visual basic 2008. I want to prevent the program from running twice if the user clicks on it more than once. Is there a setting for this? Or some other method?
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?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.