[英]Stop the installshield installation if a file is not found in vb.net
The aim of the question is to stop an installshield installation once it has started installing the service. 该问题的目的是在开始安装服务后停止installshield安装。
In particular, I want to stop the installation if a file file.txt is not found in the selected directory (the user will select the installation path). 特别是,如果在所选目录中未找到文件file.txt ,我想停止安装(用户将选择安装路径)。
To control that, I'm calling the BeforeInstall
event from ServiceInstaller
. 为了控制它,我从
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
I have tried with End
, Exit
, and many others but no one stops the installation. 我已经尝试使用
End
, Exit
和许多其他方法,但是没有人停止安装。
Clearly you can show the not found file likely by a Dialog
and call the RoleBack
method which rolls back service application information written to the registry by the installation procedure. 显然,您可以通过
Dialog
显示未找到的文件,然后调用RoleBack
方法,该方法将回滚安装过程写入注册表的服务应用程序信息。 This method is meant to be used by installation tools, which process the appropriate methods automatically. 该方法供安装工具使用,该工具会自动处理适当的方法。 (Overrides
Installer.Rollback(IDictionary)
). (重写
Installer.Rollback(IDictionary)
)。
To be aware of ServiceInstaller
methods see The MSDN . 要了解
ServiceInstaller
方法,请参见MSDN 。 And for using RollBack
method, See This MSDN Documentation which remarks : 有关使用
RollBack
方法的信息,请参阅此MSDN文档 ,该备注说明:
When you override the
Rollback
method in a derived class, be sure to call the base class'sRollback
method first in your derived method.在派生类中重写
Rollback
方法时,请确保首先在派生方法中调用基类的Rollback
方法。 A rollback operation restores the computer to the state it was in before the installations occurred.回滚操作将计算机还原到安装之前的状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.