Thanks for the link radcaesar.
During the course of yesterday's work, I came across that as well.
To others reading- make SURE you add Custom Actions for both Install and Uninstall. In both actions, do "Add Custom Action" pointing to "Application Folder \ Primary output from __YourServiceProjectName__".
Now for another issue.
When installing the service, it is not Started. Likewise, the uninstall doesn't Stop the service first...
Here are two overrides for the __YourServiceProject__\ProjectInstaller1 code:
'ServiceInstaller is by default named ServiceInstaller1 :
- Private Sub ServiceInstaller_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.AfterInstall
-
Dim displayName As String = ServiceInstaller.DisplayName
-
-
MsgBox("ServiceInstaller_AfterInstall: " & System.Reflection.Assembly.GetExecutingAssembly.Location(), MsgBoxStyle.OkOnly)
-
'find the service by display name
-
Dim scs() As ServiceController = ServiceController.GetServices()
-
Dim sc As ServiceController = Nothing
-
For Each i As ServiceController In scs
-
If (i.DisplayName = displayName) Then
-
sc = i
-
'Console.WriteLine(sc.ServiceName)
-
Exit For
-
End If
-
Next
-
If (sc Is Nothing) Then
-
'Console.WriteLine("ERROR InstallerStuff::installDotNetService() could not find installed service by display name.")
-
MsgBox("Service failed to install")
-
Return
-
End If
-
-
'start service (if not running...)
-
If (sc.Status = ServiceControllerStatus.Stopped) Then
-
sc.Start()
-
sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10))
-
If (sc.Status <> ServiceControllerStatus.Running) Then
-
MsgBox("Service failed to start." & vbCrLf & "Please start " & displayName & " via ControlPanels\Services," & vbCrLf & "...or restart computer")
-
Return
-
End If
-
End If
-
MsgBox("Service started")
-
End Sub
-
-
Private Sub ServiceInstaller_AfterRollback(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.AfterRollback
-
MsgBox("ServiceInstaller_AfterRollback", MsgBoxStyle.OkOnly)
-
End Sub
-
-
Private Sub ServiceInstaller_AfterUninstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.AfterUninstall
-
MsgBox("ServiceInstaller_AfterUninstall", MsgBoxStyle.OkOnly)
-
End Sub
-
-
Private Sub ServiceInstaller_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.BeforeInstall
-
MsgBox("ServiceInstaller_BeforeInstall", MsgBoxStyle.OkOnly)
-
End Sub
-
-
Private Sub ServiceInstaller_BeforeRollback(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.BeforeRollback
-
MsgBox("ServiceInstaller_BeforeRollback", MsgBoxStyle.OkOnly)
-
End Sub
-
-
Private Sub ServiceInstaller_BeforeUninstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles ServiceInstaller.BeforeUninstall
-
MsgBox("ServiceInstaller_BeforeUninstall " & ServiceInstaller.DisplayName, MsgBoxStyle.OkOnly)
-
Dim displayName As String = ServiceInstaller.DisplayName
-
'MsgBox("ServiceInstaller_AfterInstall: " & System.Reflection.Assembly.GetExecutingAssembly.Location(), MsgBoxStyle.OkOnly)
-
-
'find the service by display name
-
Dim scs() As ServiceController = ServiceController.GetServices()
-
Dim sc As ServiceController = Nothing
-
For Each i As ServiceController In scs
-
If (i.DisplayName = displayName) Then
-
sc = i
-
Exit For
-
End If
-
Next
-
If (sc Is Nothing) Then
-
MsgBox("Could not find service '" & displayName & "' to stop.")
-
Return
-
End If
-
-
'start service (if not running...)
-
If (sc.Status <> ServiceControllerStatus.Stopped) Then
-
sc.Stop()
-
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10))
-
If (sc.Status <> ServiceControllerStatus.Stopped) Then
-
MsgBox("Service failed to stop, but should be queued for deletion after next reboot.")
-
Return
-
End If
-
End If
-
MsgBox("Service stopped")
-
End Sub