在 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 就會自動啟動啦
沒有留言:
張貼留言