如何让我的安装程序写入HKCU注册表树? [英] How can I have my installer write to the HKCU registry tree?

查看:91
本文介绍了如何让我的安装程序写入HKCU注册表树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的安装程序需要管理员权限.在安装过程中,某些值将写入当前登录用户的注册表的HKCU树中.但是,当此用户帐户是所谓的标准帐户时,安装程​​序启动时,用户必须为管理员帐户指定凭据.然后将值写入与该管理员帐户相关的HKCU树中,而不是当前登录用户的HKCU中. 当安装程序想要将一些数据写入本地AppData并希望在桌面上创建快捷方式时,也会出现相同的问题.

My installer requires admin privileges. During installation some values are written to the HKCU tree of the registry of the currently logged on user. However, when this user account is a so called standard account, the user has to specify credentials for an administrator account when the installer starts. The values are then written to the HKCU tree pertaining to this admin account instead of the HKCU of the currently logged on user. The same problem arises when the installer wants to write some data to the local AppData and wants to create a shortcut on the desktop.

我该如何规避?

推荐答案

如果您要求管理员权限,通常意味着您正在为所有用户进行系统范围/机器安装.创建此类安装程序时,写HKCU或%USERPROFILE%并不是一个好主意,这不仅是因为您最终可能会为错误的用户"执行操作,而且最终也只会为那个用户初始化安装,并且并非所有用户.

If you are asking for admin rights it normally means you are doing a system-wide/machine install for all users. When creating this type of installer it is not a good idea to write to HKCU or %USERPROFILE%, not just because you can end up performing actions for "the wrong user" but you also end up initializing the install for just that one user and not all users.

我建议您将这些通用数据写入HKLM\Software\YourCompany\YourApp\CommonData和/或<CSIDL_COMMON_APPDATA|CSIDL_PROGRAM_FILES>\YourCompany\YourApp\CommonData,然后在用户第一次运行该数据时将其导入到您的应用程序中.

What I recommend is that you write this common data to HKLM\Software\YourCompany\YourApp\CommonData and/or <CSIDL_COMMON_APPDATA|CSIDL_PROGRAM_FILES>\YourCompany\YourApp\CommonData and then import this data in your application the first time a user run's it.

您可能还想考虑创建一个按用户安装的安装程序(例如Chrome),但这意味着您只能写入HKCU和%USERPROFILE%!

You might also want to consider creating a per-user installer (like Chrome) but this means you can only write to HKCU and %USERPROFILE%!

这篇关于如何让我的安装程序写入HKCU注册表树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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