I don't think you can prevent the OS launching a second copy of the executable but you can make them detect each other. For example one way is to create a file lock when the executable starts, so if a second instance is launched, it would try to lock that file, fail, deduce from that that there is already someone else running and exit.