Click here to Skip to main content
15,886,756 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I'm developing an C++ application for windows and this application must prevent to run more than one time in the same machine.

I want to know what ware the utilized methods to check if the application is already running, so that I can check and if one instance of this application is already running I can launch a message to the user and abort the application start.

The only thing that occurred me now is to create a flag in the windows registry, and check that flag at the beginning of the code however I could ear some experts advise.

I hope you can help,
Tanks,

Filipe
Posted

See the Joseph M. Newcomer's article: "Avoiding Multiple Instances of an Application".
:)
 
Share this answer
 
I would iterate the all processes
to try to find a running instance of a process :)

Enumerating processes : A practical approach[^]

(the mutex technique could be not enough exception-secure... :) )

[Edit]
There is a drawback: the user may use a different name for your program, and -also- the user may name another program the same as yours.
Process names are not granted to be unique.
The mutex technique is the only one that has a proper chance.
It can be exception-secure, if you manage the mutex properly.
[/Edit]

[OK]
Process names are not granted to be unique,
but their full-pathed names... :)
[/OK]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900