Hi
In many cases you may want to ensure that only one instance of your program is running. in another word,if an instance of program is running and the user tries to run a new instance,you want to found that and exit second program and maybe show an appropriate message. my question is how to implement this.
I thought about some ways like register a key in windows registry or any other thing that could use as a flag that indicate that program is running or not( by setting this flag when program runs and unset it on exiting the program) but it's a bad idea when the user kills the process or program exit with any bad status.

if you know the usual way to implement that feature, please help me