VB.NET • Hook Events Into the ProjectInstaller.vb Module

Listing A. VS.NET generates the ProjectInstaller class module that contains the properties you can use for writing Registry values for the Windows Service. In addition, you can also hook into the AfterInstall events to further customize the installation of the service.

<RunInstaller(True)> Public Class ProjectInstaller
   Inherits System.Configuration.Install.Installer

#Region " Component Designer generated code "
   Public Sub New()
      MyBase.New()

      'This call is required by the Component 
      'Designer.
      InitializeComponent()

      'Add any initialization after the 
      'InitializeComponent() call

   End Sub

   'Installer overrides dispose to clean up the 
   'component list.
   Protected Overloads Overrides Sub Dispose( _
      ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is Nothing) Then
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub

   'Required by the Component Designer
   Private components As _
      System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the 
   'Component Designer
   'It can be modified using the Component Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents _
      AppMonitorServiceProcessInstaller As _
      System.ServiceProcess.ServiceProcessInstaller
   Friend WithEvents AppMonitorServiceInstaller As _
      System.ServiceProcess.ServiceInstaller
   <System.Diagnostics.DebuggerStepThrough()> _
      Private Sub InitializeComponent()
      Me.AppMonitorServiceProcessInstaller = New _
         System.ServiceProcess.ServiceProcessInstaller
      Me.AppMonitorServiceInstaller = New _
         System.ServiceProcess.ServiceInstaller
      '
      'AppMonitorServiceProcessInstaller
      '
      Me.AppMonitorServiceProcessInstaller.Account = _
         System.ServiceProcess.ServiceAccount.LocalSystem
      Me.AppMonitorServiceProcessInstaller.Password _
         = Nothing
      Me.AppMonitorServiceProcessInstaller.Username _
         = Nothing
      '
      'AppMonitorServiceInstaller
      '
      Me.AppMonitorServiceInstaller.DisplayName = _
         "AppMonitor Service"
      Me.AppMonitorServiceInstaller.ServiceName = _
         "AppMonitor"
      '
      'ProjectInstaller
      '
      Me.Installers.AddRange(New _
         System.Configuration.Install.Installer() _
         {Me.AppMonitorServiceProcessInstaller, _
         Me.AppMonitorServiceInstaller})

   End Sub

#End Region

   Private Sub _
      AppMonitorServiceProcessInstaller_AfterInstall _
      (ByVal sender As System.Object, ByVal e As _
      System.Configuration.Install.InstallEventArgs) _
      Handles AppMonitorServiceProcessInstaller.AfterInstall

   End Sub

   Private Sub AppMonitorServiceInstaller_AfterInstall _
      (ByVal sender As System.Object, ByVal e As _
      System.Configuration.Install.InstallEventArgs) _
      zHandles AppMonitorServiceInstaller.AfterInstall

   End Sub

End Class