内存映射文件和 Win 服务 - 找不到服务器创建的文件 [英] Memory Mapped File and Win Service - Cannot find File Created By Server

查看:45
本文介绍了内存映射文件和 Win 服务 - 找不到服务器创建的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Windows 服务创建一个内存映射文件,以便它可以保存许多其他 Windows 应用程序可以使用的静态数据.

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.

我的问题是,当我启动服务时 - 该服务可以轻松读取和写入内存映射文件.但是,Windows 应用程序不能.他们收到文件未找到错误.

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.

使用同一个类来读写内存映射文件,在两个windows应用程序中我都没有问题.所以,我相信内存映射文件的使用是正确的,但还有其他东西 - 可能在我缺少的 Windows 服务领域.

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.

诚然,我对 Windows 服务不是很有经验.我试图创建简单的文件来写入我的异常,但它们也不是从服务中创建的.至于帐户,我使用的是我自己的 Windows 帐户(我的本地管理员权限有限).

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.

推荐答案

您可能需要在 MMF 名称前加上 @"Global\".我相信较新版本的 Windows 在与其他应用程序不同的会话下运行服务.

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.

我看到了对以下文章的引用:会话 0 的影响Windows 中的服务和驱动程序隔离

I saw references to the following article: Impact of Session 0 Isolation on Services and Drivers in Windows

您可能还需要修改本地安全策略创建全局对象",具体取决于您运行 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.

这篇关于内存映射文件和 Win 服务 - 找不到服务器创建的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆