如何从我的安装程序为我的用户设置此注册表值(How can I set this registry value for my User from my installer)

编程入门 行业动态 更新时间:2024-10-17 02:58:22
如何从我的安装程序为我的用户设置此注册表值(How can I set this registry value for my User from my installer)

来自https://stackoverflow.com/a/37859812/4878558的问题

我需要为启动安装的当前用户设置注册表值。 由于安装进入系统模式 - 我对当前用户一无所知

我的代码也提供'System.UnauthorizedAccessException'

SecurityIdentifier sID = WindowsIdentity.GetCurrent().User; var subKey = Registry.Users.OpenSubKey(sID + "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); subKey.SetValue("test", "test"); enter code here

The problem from https://stackoverflow.com/a/37859812/4878558

I need to set Registry value for current user, who launch the install up. Since install going for system mode - I don't know anything about current user

Also my code giving 'System.UnauthorizedAccessException'

SecurityIdentifier sID = WindowsIdentity.GetCurrent().User; var subKey = Registry.Users.OpenSubKey(sID + "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); subKey.SetValue("test", "test"); enter code here

最满意答案

正如Ripple和我都评论过的那样,不需要代码。 转到安装项目中的注册表视图,右键单击HKEY_CURRENT_USER下的软件,然后添加密钥Microsoft,然后是Windows,CurrentVersion,然后运行,添加每个密钥。

然后在Run键视图中,右键单击右侧的Name,View窗格并添加新的字符串值,该名称是您的名字。 我假设,这个值是你的exe的路径,并且(假设它在Application文件夹中)创建值[TARGETDIR] my.exe。

如果您的安装是“Everyone”安装,那么有一个很好的理由说明它无法正常工作。 这与代码无关。 在Everyone安装中,自定义操作代码与System帐户(而不是安装用户)一起运行,因此您尝试为系统帐户创建运行密钥。

As Ripple and I have both commented, there's no need for code. Go to the Registry view in the setup project, right-click on Software under HKEY_CURRENT_USER and add the key Microsoft, then Windows, the CurrentVersion, then Run, adding each key.

Then in the Run key view, right-click in the Name, View pane on the right and add new string value, the name being your name. The value, I assume, is the path to your exe, and (assuming it's in the Application folder) make the value [TARGETDIR]my.exe.

If your install is an "Everyone" install then there is a perfectly good reason why it cannot work. This is nothing to do with the code. In an Everyone install that custom action code is running with the System account (NOT the installing user) so you are trying to create a run key for the system account.

更多推荐

本文发布于:2023-08-07 00:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:安装程序   注册表   用户   set   User

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!