Windows – About Mutex object in Vista

uacwinapiwindowswindows-vista

My OS is Vista with UAC turned on, I create a global Mutex object in Server side, then my AP with UI want to use CreateMutex with same name to get the Mutex object which has been created in server, but the function tell me I don't have right to access it. How can I do it?

Best Answer

I think in your case you'll need to explicitly allow all-access to your mutex via initializing corresponding security attributes.

Try creating mutex this way (consider it as semi-pseudo-code):

SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = &sd;
CreateMutex(&sa, ...);

And by the way - it is Ok to use CreateMutex to open an existing mutex. But, OpenMutex allows you to specify required access level.

Also note, that if you need a really global mutex - you'll have to prefix it's name with "Global\" (refer to MSDN's "Kernel Object Namespaces" article)