So I did what Remy Lebeau suggessted for me, and it properly works in Windows 7, and 2008.
Here's how I went step by step.
Create a named mutex in the global namespace in the GUI application.
::CreateMutex(nullptr, false, L"Global\\MyMutex");
Check periodically if the mutex has disappeared or not by using CreateMutex(), and do not forget to take care of the reference count to the handle.
HANDLE hDetector = ::CreateMutex(nullptr, false, L"Global\\MyMutex"); if (GetLastError() == ERROR_ALREADY_EXISTS) { // The GUI application is still running. // ... ::CloseHandle(hDetector); } else { // The GUI application is not running. // ... ::CloseHandle(hDetector); }
See it work.