Getting mutex process
-
Hi, In my application, I have to get the ID or the name of the process that created a named mutex. Does anybody know how to proceed ? I use this code : HANDLE MutexHandle = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, MutexName); if (MutexHandle) { // mutex exists ::CloseHandle(MutexHandle); // how to get the process ID ? } else { // mutex doesn't exist } Thanks in advance, Robin.
-
Hi, In my application, I have to get the ID or the name of the process that created a named mutex. Does anybody know how to proceed ? I use this code : HANDLE MutexHandle = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, MutexName); if (MutexHandle) { // mutex exists ::CloseHandle(MutexHandle); // how to get the process ID ? } else { // mutex doesn't exist } Thanks in advance, Robin.
Hi, this code will resolve your problem. HANDLE m_hMutex = NULL; // Create the mutex m_hMutex = CreateMutex( NULL, FALSE, "Process.exe" ); // Check for errors if ( GetLastError() == ERROR_ALREADY_EXISTS ) { // Reset our mutext handle (just in case) m_hMutex = NULL; MessageBox(NULL,"Can't run the application twice!!!.","Task manager:",MB_OK); exit(0); } Aizik Yair Software Engineer