MemoryMappedFile.CreateOrOpen throws UnauthorizedAccessException (Access to the path is denied) RRS feed

  • Question

  • Hi,

    I am using Windows 7 machine.

    I have 2 processes. One (Process1) is run as a Windows service under the context of local system account. Other one (Process2) is run as regular Windows application.

    I am trying to create or open a Memory Managed File using the function MemoryMappedFile.CreateOrOpen("Global\\MyMMF",iSize) in both these processes.

    If I first run Process2 followed by Process1, then MemoryMappedFile.CreateOrOpen function works fine in both processes.

    But If I first run Process1 followed by Process2, MemoryMappedFile.CreateOrOpen function in Process2 fails with error UnauthorizedAccessException with exception message - "Access to the path is denied"

    I tried invoking Process2 using "Run as Admin", but no use.


    Monday, March 21, 2011 11:46 AM

All replies

  • Hi,

    I have exactly the same problem.

    There is a doucment called 'Impact of Session 0 Isolation on Services and Drivers in Windows Vista' on the web and explains that shared objects should be pre-fixed with \Global you have done this as have I. I have tried changing permissions on the Create Global Object item in the local security policy.

    My code works fine on XP SP3 but not on 2008 Server or Windows 7, with exactly the same issue as you have found.

    In my case the services will always start automatically well before any user program.

    There is a setting MemoryMappedFileSecurity that can be passed to CreateOrOpen and am wondering if with the right settings it will work. Basically I want to disble all security for the shared memory object.

    Anyone in MS looking at this?





    Thursday, March 31, 2011 9:43 AM
  • This fixed it for me:

    MemoryMappedFileSecurity CustomSecurity = new MemoryMappedFileSecurity



    CustomSecurity.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType


    _mmf =

    MemoryMappedFile.CreateOrOpen("Global\\SomeMap", 1024, MemoryMappedFileAccess.ReadWriteExecute, MemoryMappedFileOptions.None, CustomSecurity, System.IO.HandleInheritability.Inheritable);

    There are no examples of how to use MemoryMappedFileSecurity that I can find. The above was 2 hours of searching and trial and error pain!

    On a 2008 server R2 64 bit the same CreateOrOpen code works without throwing exceptions from within a .net service in session 0, admin account in session 1 and normal user account in session 2


    Thursday, March 31, 2011 11:55 AM
  • this is perfect. you don't know how long it took me to find this little gem!


    Monday, December 24, 2012 8:58 AM