来自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 hereThe 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.
更多推荐
发布评论