Hello,
Can anyone tell me what the best way is to prevent an application from
starting up twice.
Thanks,
Dirk 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
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
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
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
}
"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
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
"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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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: 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...
| |