Error 183 Createmutex
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of createmutex example this site About Us Learn more about Stack Overflow the company Business
Waitforsingleobject Mutex
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Releasemutex
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up
Openmutex
CreateMutex never returns ERROR_ALREADY_EXISTS up vote 1 down vote favorite I am using CreateMutex to stop multiple application to run certain functions at the same time. These functions are in dll so can be called over by same application or separate applictions. This dll talks to hardware so I want to return 'busy' if another function is already running rather than have to wait_abandoned wait on it. I thought best approach is to use CreateMutex instead combination of OpenMutex. int FunctionExposedByDll() { hMutexAPI = CreateMutex(0, 0, API_RUNNING_MUTEXT ); if (!hMutexAPI ) { DWORD dwErr = GetLastError(); if (dwErr == ERROR_ALREADY_EXISTS ) return MY_ERROR_BUSY; } // actual function here CloseHandle( hMutexAPI ); } So if the mutex is already created, I should get ERROR_ALREADY_EXISTS which tells me system is executing an api and I should return. However the above code always return a valid mutex even if the prior function has not returned and mutex handle is not closed. I also tried CreateMutexEx function and in that case when I try it the 2nd time it returns ERROR_ACCESS_DENIED when I am expecting ERROR_ALREADY_EXISTS. So my question is what do I need to do to get correct status that mutex already exist when it exist? I am using windows 7 **Update** Based on Rob K answer, I have changed the code to following: int FunctionExposedByDll() { hMutexAPI = CreateMutex(0, 0, API_RUNNING_MUTEXT ); DWORD dwErr = GetLastError(); if (dwErr == ERROR_ALREADY_EXISTS ) { CloseHandle( hMutexAPI); // i have to call this but it contribute
call the Win32 API using the System plug-in. See also CreateMutex plug-in. You can list all mutex objects windows waitforsingleobject using process hacker - open process properties, handles tab: Mutant, \BaseNamedObjects\myMutex, createsemaphore 0xd0 Note You should check the return value against ERROR_ALREADY_EXISTS (183) rather than 0. CreateMutex can set other createevent errors such as ERROR_ACCESS_DENIED which results in a false positive. The Script Put this code in the .onInit function: System::Call 'kernel32::CreateMutex(i 0, i 0, t "myMutex")?e' Pop $R0 StrCmp $R0 http://stackoverflow.com/questions/23547947/createmutex-never-returns-error-already-exists 0 +3 MessageBox MB_OK "The installer is already running." Abort 'myMutex' should be replaced with a unique value (e.g. "MyCompany.MyApp" or a generate a unique GUID). The advanced way This code will bring the already running instance to front, instead of opening a new one. Side Note (Jamyn): Strangely, if the user has first minimized the installer, and then tries http://nsis.sourceforge.net/Allow_only_one_installer_instance to launch another copy, the following code will correctly set the first installer as the active window, but it won't "pop" it back up from being minimized. I am not sure how to do that simply, but that may be useful. Note (Rescator): Try something like System::Call "user32::ShowWindow(i r1, i 9) i." The 9 is the flag #SW_RESTORE see PSDK for more info on ShowWindow() System::Call "kernel32::CreateMutex(i 0, i 0, t '$(^Name)') i .r0?e" Pop $0 StrCmp $0 0 launch StrLen $0 "$(^Name)" IntOp $0 $0 + 1 loop: FindWindow $1 '#32770' '' 0 $1 IntCmp $1 0 +4 System::Call "user32::GetWindowText(i r1, t .r2, i r0) i." StrCmp $2 "$(^Name)" 0 loop System::Call "user32::SetForegroundWindow(i r1) i." Abort launch: Even more advanced This uses the "advanced way" method. Unlike the function above, it will restore the window if the installer is minimized. !define INSTALLERMUTEXNAME "$(^Name)" ; TODO: Should really use a GUID here! Function .onInit BringToFront !ifndef NSIS_PTR_SIZE & SYSTYPE_PTR !define SYSTYPE_PTR i ; NSIS v2.4x !else !define /ifndef SYSTYPE_PTR p ; NSIS v3.0+ !endif System::Call 'kernel32::CreateMutex(${SYSTYPE_P
can use different name every time to createmutex.Finally, if you need to create new mutex every time rather than http://microsoft.public.win2000.developer.narkive.com/ItXa35ZA/createmutex use existedmutex, you also need to control the number of mutex.TaoI created a DLL that hooks int to a service and it ran for about 3 monthsbut now suddenly it is failing.The problem is that the CreateMutex functions in the DLL are all failingdueto Error 183 (ERROR_ALREADY_EXISTS). Even if i create error 183 the Mutex with anewname or with a NULL name i keep getting the error. what is the problem?hRunMutex = CreateMutex(NULL, TRUE, NULL );StringCbPrintf(junk,250,"hRunMutex: GetLastError %d\n", GetLastError() );Leon Alexander Grigoriev 2004-04-05 18:26:43 UTC PermalinkRaw Message If CreateMutex succeeded, LastError is not reset to zero.You can only check GetLastError if CreateMutex() call failed.Post error 183 createmutex by Tao ZhouFirst, you need to check hRunMutex if it is previous valid mutex handle, ifyou don't use, release it.Second, you can use different name every time to createmutex.Finally, if you need to create new mutex every time rather than use existedmutex, you also need to control the number of mutex.TaoI created a DLL that hooks int to a service and it ran for about 3 monthsbut now suddenly it is failing.The problem is that the CreateMutex functions in the DLL are all failingdueto Error 183 (ERROR_ALREADY_EXISTS). Even if i create the Mutex with anewname or with a NULL name i keep getting the error. what is the problem?hRunMutex = CreateMutex(NULL, TRUE, NULL );StringCbPrintf(junk,250,"hRunMutex: GetLastError %d\n",GetLastError() );Post by Tao ZhouLeon 1 Reply 4 Views Switch to linear view Disable enhanced parsing Permalink to this page Thread Navigation Tao Zhou 2004-04-05 13:22:49 UTC Alexander Grigoriev 2004-04-05 18:26:43 UTC about - legalese Loading...