private void BtnInstall_Click(object sender, EventArgs e) { string filePath = Assembly.GetExecutingAssembly().Location; var isSuccess = ServiceInstaller.InstallService(filePath); if (isSuccess) { btnInstall.Enabled = false; btnUninstall.Enabled = true; Console.WriteLine($"Install {ServiceName} success"); isSuccess = ServiceInstaller.SystemServiceOpen(ServiceName); Console.WriteLine("service start" + (isSuccess ? "success" : "failed")); if (isSuccess) { btnRestart.Enabled = true; btnStopService.Enabled = true; } } else { Console.WriteLine($"install {ServiceName} failed"); } }
private void BtnRestart_Click(object sender, EventArgs e) { ServiceInstaller.SystemServiceReStart(ServiceName); Console.WriteLine($"{ServiceName} has been restarted"); }