I am trying to use memory mapped files to exchange data between windows (written in C #) and a splash screen written in C ++.
Although this works well if the screensaver works in the context of a registered user, it does not work if the screensaver works on the login screen. Instead, OpenFileMapping crashes with an unauthorized access error. It seems obvious that I donβt have an access rule (or maybe a system setup to do this), but I canβt figure out which one.
My C # code:
public CreateMemMappedFile(string fileName) { this.rootName = fileName; var security = new MemoryMappedFileSecurity(); security.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>( new SecurityIdentifier(WellKnownSidType.WorldSid, null), MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)); security.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>( new SecurityIdentifier(WellKnownSidType.AnonymousSid, null), MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)); security.AddAccessRule(new System.Security.AccessControl.AccessRule<MemoryMappedFileRights>( new SecurityIdentifier(WellKnownSidType.NullSid, null), MemoryMappedFileRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
My screensaver code:
TCHAR* myFileName = _T("Global\\myfile"); ipcBufferHandle = OpenFileMapping(FILE_MAP_READ,FALSE,myFileName); if(ipcBufferHandle == NULL) { _tprintf(_T("couldn't open file \"%s\" with error code %d\n"),myFileName,GetLastError()); } else { _tprintf(_T("opened file %s\n"),myFileName); }
which outputs couldn't open file "Global\myfile" with error code 5
source share