CreateMutex - "Access Denied"

The following code works without any problems, sometimes, and at other times it throws an "Access Denied" error. The behavior is incompatible.

_hMutex = CreateMutex(NULL, FALSE, MutexName);
    if (_hMutex == NULL) 
{
  throw MY_ERROR(GetLastError(), L"Error creating mutex handle");
}

I run my standalone executable that has this code, performs an operation, and shuts down. This is not a multithreaded application. I log in with the same user credentials every time I run this.

Could you help me solve this problem?

Thanks Hem

+3
source share
3 answers

I finally found it. There is a service that works with a system account that creates a mutex and exe, launched by the user, trying to access it. It was because of permission.

0
source

, , , GetLastError ERROR_ALREADY_EXISTS, bInitialOwner , .

, , ERROR_ACCESS_DENIED, OpenMutex.

MSDN

+2

, , MutexName . , ( , ) .

. MSDN. :

If the mutex is a named mutex, and the object existed before, the call of the [elided] function, if the caller has limited access rights, the function will not work with ERROR_ACCESS_DENIED, and the caller should use the OpenMutex function.

+1
source

All Articles