Using file mapping in different sessions on Windows

陌路散爱 提交于 2020-07-09 12:01:31

问题


I using CreateFileMapping and MapViewOfFile to use a file as Shared storage between two process.

The process A, it is running as Service in session 0, to clear the content in file mapping.

The process B, it is a normal process run in session 1, to read and write the content in file mapping.

Using process B first, there has some data were stored into file mapping and terminates. Then, run the Process A to clear data. In my expectation, after execute process A, the file mapping would become empty. But It didn't.

And if I change the privilege of Process A, running it as normal process and in session 1. All of them are works correctly.

My question is, the file mapping with same name are not identical between different session on windows?

And does there has any function can create a thread to run in session 1 from a process in session 0? (I have tried impersonate as user session before create_thread in the process of session 0, it doesn't work)

Thank you.


回答1:


The name must be prefixed with Global\ if you want to access the object from different sessions.

To avoid security issues you also want the service to create the object:

The creation of a file-mapping object in the global namespace, by using CreateFileMapping, from a session other than session zero is a privileged operation. Because of this, an application running in an arbitrary Remote Desktop Session Host (RD Session Host) server session must have SeCreateGlobalPrivilege enabled in order to create a file-mapping object in the global namespace successfully. The privilege check is limited to the creation of file-mapping objects, and does not apply to opening existing ones. For example, if a service or the system creates a file-mapping object, any process running in any session can access that file-mapping object provided that the user has the necessary access.



来源:https://stackoverflow.com/questions/43802058/using-file-mapping-in-different-sessions-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!