windows 使用 RegCreateKeyEx 给出错误代码 5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7656794/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:12:03  来源:igfitidea点击:

using RegCreateKeyEx gives error code 5

windows32bit-64bitregistry

提问by surendran

I used RegCreateKeyEx from a win32 application(VisualStudio 2008) in 64 bit windows(Project built with target x64). It was able to create a registry entry. Now I have a dll file (Project built with target x64) which too wanna create registry entry but my dll is returning error code 5(Yeah! its a sign of access denied). My samDesiredflag have KEY_ALL_Access+ In linker->manifestfile->run as administrator chosen which still fails with error code 5. Whereas it works perfectly in 32bit windows(Project built with target x86). Am i missing something? NOTE:I'm trying to create an entry at HKEY_LOCAL_MACHINE.

我在 64 位窗口(使用目标 x64 构建的项目)中使用了来自 win32 应用程序(VisualStudio 2008)的 RegCreateKeyEx。它能够创建一个注册表项。现在我有一个 dll 文件(使用目标 x64 构建的项目),它也想创建注册表项,但我的 dll 返回错误代码 5(是的!这是访问被拒绝的标志)。我的samDesired标志有KEY_ALL_Access+ In linker->manifestfile->run as administrator selected,但仍然失败并显示错误代码 5。而它在 32 位 Windows(使用目标 x86 构建的项目)中完美运行。我错过了什么吗? 注意:我正在尝试在 HKEY_LOCAL_MACHINE 创建一个条目。

回答by Harry Johnston

You can't create a registry key in HKEY_LOCAL_MACHINEbecause this isn't a hive. You need to put your key in HKEY_LOCAL_MACHINE\Softwareor (less probably) one of the other hives.

您无法在其中创建注册表项,HKEY_LOCAL_MACHINE因为这不是配置单元。您需要将钥匙放入HKEY_LOCAL_MACHINE\Software或(不太可能)其他蜂箱之一。

I don't know why this appeared to work when you were running 32-bit code in WOW64, perhaps this is a side-effect of the way the 32-bit view of the registry is presented.

我不知道为什么当您在 WOW64 中运行 32 位代码时这似乎有效,也许这是注册表的 32 位视图呈现方式的副作用。