windows 系统错误 0x5:CreateFileMapping()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3999157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System Error 0x5: CreateFileMapping()
提问by Bunkai.Satori
I wish to implement IPC using Named Shared Memory.
我希望使用命名共享内存来实现IPC。
To do this, one of the steps is getting a handle to a Mapping Memory Object, using CreateFileMapping().
为此,其中一个步骤是使用CreateFileMapping()获取Mapping Memory Object的句柄。
I do it exactly as MSDN website reccommends: http://msdn.microsoft.com/en-us/library/aa366551(v=VS.85).aspx:
我完全按照 MSDN 网站推荐的方式进行操作:http: //msdn.microsoft.com/en-us/library/aa366551(v=VS.85) .aspx:
hFileMappingHandle = CreateFileMapping
(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
256, // maximum object size (low-order DWORD)
"Global\MyFileMappingObject" // name of mapping object
);
DWORD dwError = GetLastError();
However, the handle returned is always 0x0, and the System Error Codereturned is: 0x5 (Access Denied.)
但是,返回的句柄始终为0x0,返回的系统错误代码为:0x5 (拒绝访问。)
- Only Named Memory Sharingdesired (not file sharing).
- Windows 7 x64bit OS
- Administrator'suser rights available
- Developed Application: 64bit Plug-In application (.dll)
- 只需要命名内存共享(不是文件共享)。
- Windows 7 x64位操作系统
- 管理员用户权限可用
- 开发的应用程序:64位插件应用程序(.dll)
Does anybody have the same experience, and a way to fix it, please? I use MSDN site as my reference, so I to not think, there is problem in the code.
有没有人有同样的经历,求解决方法?我使用 MSDN 站点作为我的参考,所以我不认为代码有问题。
采纳答案by Eugene Mayevski 'Callback
Looks like you don't have enough privileges.
看起来你没有足够的权限。
From MSDN:
来自 MSDN:
Creating a file mapping object in the global namespace from a session other than session zero requires the SeCreateGlobalPrivilege privilege. For more information, see Kernel Object Namespaces.
...
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.
从会话零以外的会话在全局命名空间中创建文件映射对象需要 SeCreateGlobalPrivilege 权限。有关更多信息,请参阅内核对象命名空间。
...
通过使用 CreateFileMapping,从会话零以外的会话在全局命名空间中创建文件映射对象是一种特权操作。因此,在任意远程桌面会话主机(RD 会话主机)服务器会话中运行的应用程序必须启用 SeCreateGlobalPrivilege 才能在全局命名空间中成功创建文件映射对象。权限检查仅限于创建文件映射对象,不适用于打开现有对象。例如,如果一个服务或系统创建了一个文件映射对象,则在任何会话中运行的任何进程都可以访问该文件映射对象,前提是用户具有必要的访问权限。
回答by alemjerus
Administrators, Services and Network Services have SeCreateGlobalPrivilege by default. You must remember though, that Windows7/Vista does not run everything as admin. So use "Start as administrator" to make "Global\" work for your application. If you're debugging, start Visual Studio as admin also.
默认情况下,管理员、服务和网络服务具有 SeCreateGlobalPrivilege。但是您必须记住,Windows7/Vista 不会以管理员身份运行所有内容。因此,使用“以管理员身份启动”使“全局\”适用于您的应用程序。如果您正在调试,也请以管理员身份启动 Visual Studio。
回答by Steve Townsend
To create global file mappings you need the SeCreateGlobalPrivilege
privilege - do you have that? Access-denied implies this is a permissions problem, for sure.
要创建全局文件映射,您需要SeCreateGlobalPrivilege
特权 - 您有吗?拒绝访问意味着这是一个权限问题,当然。
回答by Dave Bush
The reference to terminal services in the documentation about global namespace is a bit misleading as it implies you only need to worry about this if you have an unusual situation.
关于全局命名空间的文档中对终端服务的引用有点误导,因为它暗示您只有在遇到异常情况时才需要担心这一点。
In fact both IIS and system services run in session zero, and the first / only user to log on runs in session 1 - so you have to use Global namespace to communicate between IIS or a service and a normal program.
事实上,IIS 和系统服务都在会话 0 中运行,第一个/唯一登录的用户在会话 1 中运行 - 因此您必须使用全局命名空间在 IIS 或服务与普通程序之间进行通信。