Question

We have an issue with the way we are creating a Mutex. The problem line is:

MutexAccessRule rule = new MutexAccessRule("Everyone", MutexRights.FullControl, AccessControlType.Allow);

The hardcoded "Everyone" string only works on English OSes, how do we change this line so it works in all languages?

Was it helpful?

Solution

Google is being helpful today:

Looks like this will help

This code solves this problem:

  SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
  MutexAccessRule rule = new MutexAccessRule(sid, MutexRights.FullControl, AccessControlType.Allow);

VB:

Dim sid As System.Security.Principal.SecurityIdentifier = New System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, Nothing)
Dim rule As System.Security.AccessControl.MutexAccessRule = New System.Security.AccessControl.MutexAccessRule(sid, System.Security.AccessControl.MutexRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)

OTHER TIPS

I had the same problem, but needed the actual localized string of the "Everyone" group name in order to enable access to a MessageQueue. Here's the solution I found, which works fine:

SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var acct = sid.Translate(typeof(NTAccount)) as NTAccount;
myMessageQueue.SetPermissions(acct.ToString(), MessageQueueAccessRights.FullControl); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top