c# windows service 安裝後自動啟動,與InstallUtil.exe安裝與反安裝
public ProjectInstaller()
{
InitializeComponent();
this.AfterInstall += new InstallEventHandler(ProjectInstaller_AfterInstall);
}
void ProjectInstaller_AfterInstall(object sender, InstallEventArgs e)
{
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("Tittan_Service");
if (sc != null)
sc.Start();
}
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe C:/Tittan_Service.exe (安裝)
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe C:/Tittan_Service.exe /u (反安裝)
參考:http://blog.gclin.org/2009/05/c-sharp-wndows-service-timer-setup/