Stop the installshield installation if a file is not found in vb.net

197 views Asked by At

The aim of the question is to stop an installshield installation once it has started installing the service.

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).

To control that, I'm calling the BeforeInstall event from ServiceInstaller.

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.

1

There are 1 answers

3
Amirhossein Mehrvarzi On

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. This method is meant to be used by installation tools, which process the appropriate methods automatically. (Overrides Installer.Rollback(IDictionary)).

To be aware of ServiceInstaller methods see The MSDN. And for using RollBack method, See This MSDN Documentation which remarks :

When you override the Rollback method in a derived class, be sure to call the base class's Rollback method first in your derived method. A rollback operation restores the computer to the state it was in before the installations occurred.