Hello all :) Say i have written a program. I want to keep the program from running twice at the same time. I mean, i am trying to get my program to check if it is already running. Because of the program nature (a small game) it already writes a registry key when it begins, and deletes the registry key before it exits. So i ask, how can i check for this registry key? I already have the null terminated string to compare it to. Should i use OpenRegKey? or CreateRegKey? Anyone know how comparing Registry entries is done? Thanks! -Jumpsteady44
Posted on 2001-05-16 10:48:00 by Jumpsteady44
Jumpsteady44, Well, you could use CreateRegKey (using CREATE_NEW) at startup of your program. If it doesn't exist the key will be created, if it does the call will fail having as error the ERROR_ALREADY_EXISTING ... (Well, more or less.... I don't have the API guide here as I'm at work, but basically it's what you want to do.) This got added: Erm.. I forgot.. there are much nicer methods of preventing multiple instances of your program... Do a board search using "instance" as keyword and you will get several threads explaing different methods avoiding 'clones' :D This message was edited by JimmyClif, on 5/16/2001 11:32:46 AM
Posted on 2001-05-16 11:29:00 by JimmyClif
If you stop multiple instances using any method that requires "clean up" at then end of execution have one major failing... If your program is rudely interupted (power cut, killed, crash etc.) your program will never run again! Obviously you can tell the user to edit the register, but remember there are a lot of idiots using computers out there! There are definitly better ways of doing what you want, and several have been discussed on the board, all you need to do is search for them! Mirno
Posted on 2001-05-16 11:43:00 by Mirno
In reply to the latest post.. =) You could add a key at exit telling the program at startup that it was closed fine. And if that key doesn't exist the program will start =) No matter that first key says.. //Phrekie
Posted on 2001-05-17 17:27:00 by Phrekie