VS Setup - 关于Windows Service

前面写过一篇使用VS Setup项目作安装包的总结 ,今天补充两点关于打包Windows Service的tips:

1. 如何安装windows service? - 使用service installer

2. 如何在安装向导完成后,启动刚安装完成的service?

   2.1 使用Custom Action并在Installer的Committed事件中启动service

   2.2 将此Custom Action 添加到安装项目的Custom Actions 编辑器的Commit节中

 

Custom Action代码示例如下:

 

Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.ComponentModel

<RunInstaller(True)> _
Public Class CustomActionManager
    Inherits Installer
    Private Const Service_Name As String = "MyService"

    Public Sub New()
        MyBase.New()

        AddHandler Committed, AddressOf CustomActionManager_Committed
    End Sub

    Private Sub CustomActionManager_Committed(ByVal sender As Object, ByVal e As InstallEventArgs)
      
        'need to put this custom action under the Commit section of Setup -> Custom Actions wizard
        Dim svcController As New ServiceController(Service_Name)
        Try
            svcController.Start()
        Catch ex As Exception
            MsgBox("failed to start service " + Service_Name)
        Finally
            svcController.Dispose()
        End Try
    End Sub

End Class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值