none
OpenFileMapping() GetLastError() says Access denied

    Question

  • Hello,

       I have a process which runs in LocalSystem account in Win2k8 server and creates named file mapping object thru CreateFileMapping(). Another process which runs through logged in account has to open the created file mapping object to write thru OpenFileMapping().

     

    But OpenFileMapping() fails and returns GetLastError() 5 - Access denied.

    ________________________________________________

     

    SECURITY_DESCRIPTOR securityDescriptor;

    LPSECURITY_ATTRIBUTES pattr = new SECURITY_ATTRIBUTES;

    pattr->nLength = sizeof(LPSECURITY_ATTRIBUTES);

    pattr->lpSecurityDescriptor = &securityDescriptor;

    pattr->bInheritHandle = TRUE;

    InitializeSecurityDescriptor(pattr->lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION) ;

    SetSecurityDescriptorDacl(pSD, TRUE, NULL, FALSE);

     

    //Process -1

    CString strPathFilename = c:\\windows\\xyz;

    char *shmPath_in = "Global\\XYZ";

    HANDLE hSharedFile,hFileMapObj;

     

    hSharedFile=CreateFile( strPathFilename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, pattr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

     

    hFileMapObj=CreateFileMapping(hSharedFile, pattr, PAGE_READWRITE, 0,

    3000, shmPath_in);

     

    pShmPtr_=(char*) MapViewOfFile(hFileMapObj,FILE_MAP_WRITE,0,0,0);

     

    // process -2

    hFileMapObj = OpenFileMapping(FILE_MAP_WRITE, FALSE, shmPath_in);

    ________________________________________________________________

     

    If anyone knows the reason for the failure plz let me know

    Thanks in advance,

    Arjun

    Tuesday, May 13, 2008 5:33 PM

All replies

  • Hmm, does the same code work on XP?

    Process 2 wouldn't happen to run at low integrity (within protected mode IE), would it?

     

    Friday, May 23, 2008 8:21 PM
  • I have similar problem. Process 2 runs at low integrity (within protected mode IE8).  It works in Vista/IE8, Windows 7/IE8, but it doesn't work on Windows XP and IE8

    Saturday, February 19, 2011 12:50 AM