在 PorjectInstaller 內註冊 AfterInatall Event,搭配 ServiceController 在安裝後自動啟動 Service
using System.ServiceProcess;
namespace WalkthroughWindowsService
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
InitializeComponent();
AfterInstall += (sender, e) =>
{
ServiceController sc = new ServiceController(serviceInstaller1.ServiceName);
if (sc != null)
sc.Start();
};
}
}
}
安裝後 Service 就會自動啟動啦![[C#] Windows Service - 安裝後自動執行-1](https://c1.staticflickr.com/1/275/31513638094_c488b85b75_z.jpg)
![[C#] Windows Service - 安裝後自動執行-2](https://c1.staticflickr.com/1/568/32356079705_5257640146_z.jpg)
沒有留言:
張貼留言