问题
I am trying to create a memory mapped file with a windows service so it can hold a lot of static data that other windows applications can use.
My issue is that when I start the service - the service can read and write the memory mapped file easily. However, the windows apps cannot. They get a file not found error.
Using the same class to read and write the memory mapped file, in two windows applications I have no issues. So, I am under the belief that the use of the memory mapped files is correct but there is something else - probably in the realm of windows services that I am missing.
I have tried to add an access control but that does not help. Still, file not found.
Admittedly, I am not very experienced with windows services. I have tried to create simple files to write my exceptions into but they are not being created from the service either. As for the account, I am using my own windows account (I have limited, local admin privs).
I am not using the Network Services account because I need to access a database with credentials embedded in my user account.
Any ideas would be awesome because I have started to spin my wheels at this point.
回答1:
You might need to prepend the MMF name with @"Global\". I believe the newer versions of Windows runs services under a different session than other apps.
I saw references to the following article: Impact of Session 0 Isolation on Services and Drivers in Windows
You might also need to modify the Local Security Policy "Create global objects", depending on what user account you are running your windows app from.
来源:https://stackoverflow.com/questions/11301978/memory-mapped-file-and-win-service-cannot-find-file-created-by-server