Creating Global MMFs with full access
===

I'm using Memory Mapped Files with .NET, C# to pass data between processes on a Windows machine. I'm also using a mutex for synchronization.

I had to make the MMFs and the Mutex Global (by adding "Global\\" to their names) because the processes can be run by different users at the same time. 

The MMFs and the Mutex are created by the first process that happens to run, and the other processes just open the existing MMFs whenever they need to Read/Write to it:

            this.mutex = new Mutex(true, MUTEX_NAME, out mutexCreated);

            if (mutexCreated)
            {
                using (MutexWrapper mutexWrapper = new MutexWrapper(this.mutex))
                {
                    SetMutexAccess();
                    // If first to create mutex, also create the environment and the MMFs
                    CreateEnvironment();
                }
            }
            else
            {
                // Else Open existing MMF
                using (MutexWrapper mutexWrapper = new MutexWrapper(this.cacheMutex))
                {
                    mutexWrapper.AcquireMutex();
                    OpenEnvironment();
                }
            }

The problem is that I get a System.UnauthorizedAccessException if the first process (the one that will create the MMFs) does not run on an admin account. 

This is the code for creating the MMFs:

    private void CreateMMFs() //set access rights on MMF creation
        {
            FileSecurity fileSecurity = GetFileSecurity();
            MemoryMappedFileSecurity mmfSecurity = GetMMFAccessSecurity();
    
            MMFResources = MemoryMappedFile.CreateFromFile(File.Create(MMF_RESOURCES_FILE, 1, FileOptions.None, fileSecurity), MMF_RESOURCES_NAME, MMF_RESOURCES_CAPACITY, MemoryMappedFileAccess.ReadWrite, mmfSecurity, HandleInheritability.None, true);
            
            MMFDependencies = MemoryMappedFile.CreateFromFile(File.Create(MMF_DEPENDENCIES_FILE, 1, FileOptions.None, fileSecurity), MMF_DEPENDENCIES_NAME, MMF_DEPENDENCIES_CAPACITY, MemoryMappedFileAccess.ReadWrite, mmfSecurity, HandleInheritability.None, true);
        }

        private FileSecurity GetFileSecurity()
        {
            FileSystemAccessRule accessRule = new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, AccessControlType.Allow);
            FileSecurity security = new FileSecurity();
            security.AddAccessRule(accessRule);
            return security;
        }

        private MemoryMappedFileSecurity GetMMFAccessSecurity()
        {
            AccessRule<MemoryMappedFileRights> accessRule = new AccessRule<MemoryMappedFileRights>(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MemoryMappedFileRights.FullControl, AccessControlType.Allow);
            MemoryMappedFileSecurity mmfSecurity = new MemoryMappedFileSecurity();
            mmfSecurity.SetAccessRule(accessRule);
            return mmfSecurity;
        }

The error:

    System.UnauthorizedAccessException
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
	   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateCore(SafeFileHandle fileHandle, String mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
	   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(FileStream fileStream, String mapName, Int64 capacity, MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity, HandleInheritability inheritability, Boolean leaveOpen)
	   (...)

If I create the MMFs from a process that runs on an admin account, I have no problem in opening/reading/writing it from another processes. But when I try to create it from an user acount, I keep getting this error. Is that because it's only possible to create a Global MMF with full access rights from an admin account ?

Sorry for the long question, but this is a really big issue for me. I was even thinking on throwing away the MMFs and using disk files, despite the decrease in performance.

Thanks