是否可以在 C# 中单击按钮而不是在设置自定义操作中调用安装程序类?

发布于 2024-10-16 03:46:31 字数 146 浏览 2 评论 0原文

如果用户没有管理员权限。如何在按钮单击事件上调用安装程序类,该事件从注册表中读取数据并将值写入 C# 中的注册表?

因为当用户进行注册时我收到错误,它会在注册表中写入值,并且用户无权写入注册表。所以我知道只有安装程序类才有权利这样做。那么我怎样才能做到这一点呢?

If the user does not have admin permissions. How can I call the installer class on the button click event which reads from the registry and also write a value to the registry in c#?

Because I am getting an error when the user goes to registration it writes value in registry and the users do not have rights to write to registry. So i know that only the installer class has the right to do that. So how can I make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久随 2024-10-23 03:46:31

推荐的方法是使用两种不同的自定义操作:

  • 一种在安装 UI 中读取数据(您的注册表值),
  • 另一种在 InstallExecuteSequence(安装期间)中写入数据,

这样您就不会遇到权限问题。

The recommended approach is to use two different custom actions:

  • one in the installation UI which reads data (your registry value)
  • the other in InstallExecuteSequence (during install) which writes data

This way you shouldn't have permission problems.

最单纯的乌龟 2024-10-23 03:46:31

没有一个可能有效的理由想要这样做。安装程序类自定义操作无法访问 MSI 句柄。这意味着他们无法获取/设置属性。唯一可用于更改计算机的配置,这违背了从用户界面序列中执行此操作的所有 Windows Installer 最佳实践。

UI 中按钮上唯一应该做的事情是验证处理,必须在进入下一个对话框之前完成。一个示例是验证用户输入,例如用于连接到 SQL 服务器的凭据。连接到 SQL Server 并使用它执行某些操作的繁重工作应该作为执行序列中的延迟自定义操作来完成。

我建议研究一下 WiX DTF。这公开了比安装程序类自定义操作更多的功能,并允许您创建遵循最佳实践的解决方案。

There isn't one possibly valid reason to want to do this. Installer class custom actions have no access to the MSI handle. This means they can't get/set properties. The only thing that can be used for is to change the configuration of the machine and it goes against all Windows Installer best practices to do this from within the User Interface Sequence.

The only thing that should be done on a button in the UI is validation processing that must be done before going to the next dialog. An example would be validating user input such as credentials for connecting to a SQL server. The heavy lifting of connecting to the SQL server and doing something with it should be done as deferred custom actions in the execute sequence.

I suggest looking into WiX DTF. This exposes more functionality then Installer class custom actions and allows you to create solutions that follow best practices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文