【问题标题】:Stop the installshield installation if a file is not found in vb.net如果在 vb.net 中找不到文件,请停止 installshield 安装
【发布时间】:2015-06-15 23:09:33
【问题描述】:

问题的目的是在 installshield 开始安装服务后停止安装。

特别是,如果在所选目录中找不到文件file.txt,我想停止安装(用户将选择安装路径)。

为了控制它,我从ServiceInstaller 调用BeforeInstall 事件。

Private Sub ServiceInstaller1_BeforeInstall(sender As Object, e As InstallEventArgs) Handles ServiceInstaller1.BeforeInstall
    Dim filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace("\", "\\")
    If Not File.Exists(filePath) & "\file.txt" Then
        MsgBox("The specified file is not found in that path, the installation will stop.")
        'Missing code
    End If
End Sub

我尝试了EndExit 和许多其他人,但没有人停止安装。

【问题讨论】:

  • 您可能想显示一个Dialog,然后决定关闭 installshield 托架,在您的程序中调用类似 return 0 的内容
  • 什么样的对话框?我怎样才能做到这一点?请再解释一下。
  • Dialog 窗口,一种常见的通知用户的方式,可能通过添加“确定”或“取消”按钮等决定来通知用户。
  • 是的,我明白了。我的意思是,使用那个对话框窗口,我怎样才能停止安装进行回滚?

标签: vb.net events installation installshield


【解决方案1】:

显然,您可以通过Dialog 显示未找到的文件并调用RoleBack 方法,该方法回滚安装过程写入注册表的服务应用程序信息。此方法旨在由安装工具使用,这些工​​具会自动处理适当的方法。 (覆盖Installer.Rollback(IDictionary))。

要了解ServiceInstaller 方法,请参阅The MSDN。而对于使用RollBack 方法,请参阅This MSDN Documentation 其中备注:

当您在派生类中重写 Rollback 方法时,请务必 首先在派生方法中调用基类的Rollback 方法。一个 回滚操作将计算机恢复到之前的状态 安装完成。

【讨论】:

  • 我明白了...我怎样才能获得安装前的状态?我必须使用 IDictionary?我该如何使用它?
  • @Asa 哦,我的错误:(我输入了两次链接(重复)。检查我的答案中的第二个链接,它现在指向另一个页面。
  • @Asa 安装前您无法访问savedState!因为它属于类! public override void Rollback( IDictionary savedState )
猜你喜欢
  • 2013-05-18
  • 2023-03-22
  • 1970-01-01
  • 2022-08-16
  • 1970-01-01
  • 2020-09-28
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
相关资源
最近更新 更多