简体   繁体   English

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

[英]Is it possible to call installer class on button click in c# not in setup Custom Action?

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#? 如何在按钮单击事件中调用安装程序类,该事件从注册表读取并在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? 那么我该如何做呢?

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 另一个在InstallExecuteSequence中(在安装过程中),用于写入数据

This way you shouldn't have permission problems. 这样,您应该不会有权限问题。

There isn't one possibly valid reason to want to do this. 没有一个可能的正当理由要这样做。 Installer class custom actions have no access to the MSI handle. 安装程序类的自定义操作无权访问MSI句柄。 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. 唯一可以使用的方法是更改​​计算机的配置,这与所有Windows Installer最佳做法都无法从用户界面序列中进行。

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. 在UI中的按钮上唯一要做的就是验证处理,该处理必须在进入下一个对话框之前完成。 An example would be validating user input such as credentials for connecting to a SQL server. 一个示例是验证用户输入,例如用于连接到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. 连接到SQL Server并对其进行处理的繁重工作应作为执行序列中的延迟自定义操作来完成。

I suggest looking into WiX DTF. 我建议研究WiX DTF。 This exposes more functionality then Installer class custom actions and allows you to create solutions that follow best practices. 这将提供比Installer类自定义操作更多的功能,并允许您创建遵循最佳实践的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM