How to check if program is already running

I only want my application to run once at a time. If it's already running and the user runs it again, it should close automaticly. Basicly the program should get it's name and check if it's running as a task. If so, it should quit.
you can create global synchronization point (like event or mutex) which is set with main instance of the program, and other instances check if it is set or not. ie.:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx

hPrevInstance [in]

Type: HINSTANCE

A handle to the previous instance of the application. This parameter is always NULL. If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first [...]
Topic archived. No new replies allowed.