service and User Interface App shared memory in c# RRS feed

  • Question

  • If I write following in service:

        mmfKernel = MemoryMappedFile.CreateNew("Global\\myMMF", 1024);

    and following in user app:

        MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("Global\\myMMF");

    I get access denial to global mmf. How to grant access rights to mmfKernel to everyone with all possible rights?

    But the other way round, 
    following in user app after I acquire SeCreateGlobalPrivilege:

        mmfKernel = MemoryMappedFile.CreateNew("Global\\myMMF", 1024);

    and following in service:

        MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("Global\\myMMF");

    I get path access denial while creating mmfKernel even though I have already SeCreateGlobalPrivilege. 
    How to create it as normal user but not admin?
    Sunday, December 8, 2019 4:57 PM

All replies

  • In case of semaphores, try this name: @“Global\graŻabkaSemaphore”.

    In case of memory-mapped files, did you also try a real file accessible by both programs, using MemoryMappedFile.CreateFromFile?

    Sunday, December 8, 2019 8:32 PM
  • I did following in ring1 service:

                bool czyZnalazłSemaphore = true;
                SemaphoreSecurity semSec = new SemaphoreSecurity();
                SemaphoreAccessRule rule = new SemaphoreAccessRule("OKARDAKONUR\\okardak", SemaphoreRights.FullControl, AccessControlType.Allow);
                Semaphore semaphoreObject = new Semaphore(1, 1, @"Global\graŻabkaSemaphoree", out czyZnalazłSemaphore, semSec);

    How to grant full rights over semaphore to everyone?
    Tuesday, December 10, 2019 12:48 AM
  • can do Global in MemoryMappedFiles as well but how?
    Tuesday, December 10, 2019 8:00 PM
  • Hi zweigs Korba Shael, 

    Thanks for your feedback.

    For your question,  you get path access denial while creating mmfKernel.

    You can try the following code.

                var security = new MemoryMappedFileSecurity(); 
                security.AddAccessRule(new AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl, AccessControlType.Allow));
                MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen(@"Global\myMMF", 1024 * 1024, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.DelayAllocatePages, security, HandleInheritability.Inheritable);

    Besides, Here are two references about the exception.

    1. MemoryMappedFile.CreateOrOpen throws UnauthorizedAccessException (Access to the path is denied)
    2. .net 4.0 creating a MemoryMappedFile with global context throws exception

    Hope them can help you.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, December 11, 2019 9:42 AM