private void btnInstall_Click(object sender, EventArgs e) { try { File.Copy("config.txt", "C:\\config.txt", true); } catch (Exception ex) { } if (ServiceInstaller.ServiceIsInstalled(MY_SERVICE)) { ServiceInstaller.StopService(MY_SERVICE); ServiceInstaller.Uninstall(MY_SERVICE); } else { string exe_path = Application.ExecutablePath; String dir_path = Path.GetDirectoryName(exe_path); String service_path = dir_path + "/" + "window99.exe"; ServiceInstaller.InstallAndStart(MY_SERVICE, MY_SERVICE, service_path); } showServiceState(); }
private void showServiceState() { ServiceState state = ServiceInstaller.GetServiceStatus(MY_SERVICE); txtState.Text = state.ToString(); if (ServiceInstaller.ServiceIsInstalled(MY_SERVICE)) { btnInstall.Text = "Uninstall"; } else { btnInstall.Text = "Install"; } if (state == ServiceState.Running) { btnStart.Text = "Stop"; } else { btnStart.Text = "Start"; } }