从应用程序中访问 Win 7 上的 HKLM 注册表分支 [英] Access to HKLM registry branch on Win 7 from within application

查看:53
本文介绍了从应用程序中访问 Win 7 上的 HKLM 注册表分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从应用程序写入 Win 7 中的 HKLM 注册表分支?

Is it possible to write to the HKLM registry branch in Win 7 from an application?

我现有的代码无法在 Win 7 机器上写入 HKLM 注册表分支,而它能够在 XP 机器上执行此操作.

My existing code is not able to write to the HKLM registry branch on Win 7 machines, while it is able to do this on XP machines.

如何在 Win 7 上允许应用程序对 HKLM 进行读/写访问,或者所有应用程序现在都应该改用 HKCU?如果我需要基于机器而不是用户来存储设置怎么办?

How do you allow an application read/write access to HKLM on Win 7, or should all applications now just use HKCU instead? What if I need to store settings on a machine basis rather than a user basis?

推荐答案

您需要决定是编写管理应用程序(通过写入 HKLM)故意更改所有用户的设置还是普通应用程序,它不会.如果您确实在编写管理应用程序,那么在其上放置一个清单,其中包含 requireAdministratorrequestedExecutionLevel.用户每次运行应用程序时都会收到 UAC 提示,但您对 HKLM 的写入会成功.或者,将应用更改为写入 HKCU 或其他某个用户存储.

You need to decide whether you are writing an administrative app, that deliberately changes settings for all users (by writing to HKLM) or an ordinary app, that does not. If you really are writing an administrative app then put a manifest on it that has a requestedExecutionLevel of requireAdministrator. The user will get a UAC prompt every time they run the app, but your writes to HKLM will succeed. Alternatively, change the app to write to HKCU or some other per-user store.

(不知道如何添加清单?告诉我您使用的是什么语言/IDE,我会尽力提供帮助.)

(No idea how to add a manifest? Tell me what language/IDE you're using and I'll try to help.)

依赖虚拟化是个坏主意.它的实现是为了让未显示的应用程序至少有点工作.总有一天它会消失,但它在这里时并不是那么好.

Relying on virtualization is a bad idea. It was implemented to let unmanifested applications at least sorta kinda work. It will go away some day and is not that great while it's here.

这篇关于从应用程序中访问 Win 7 上的 HKLM 注册表分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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