private void btnChangeStartType_Click(object sender, EventArgs e) { if (MessageBox.Show("Change service start type to '" + cmbStartType.SelectedItem.ToString() + "'?", "Service Properties", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, (ServiceStartMode)cmbStartType.SelectedItem); MakeGUI(false); } }
private void FormInstallService_Shown(object sender, EventArgs e) { string path = SystemVariables.ApplicationDirectory + @"\gView.MapServer.Tasker.exe"; FileInfo fi = new FileInfo(path); if (fi.Exists) { ServiceInstaller c = new ServiceInstaller(); if (_action == Action.Install || _action == Action.Install_forced) { if (_action != Action.Install_forced) { try { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); ServiceControllerStatus status = sc.Status; // Serive already installed!! txtOutput.Text = "Service 'gView.MapServer.Tasker' allready installed..."; _succeeded = true; this.Refresh(); Thread.Sleep(2000); this.Close(); return; } catch { } } try { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceControllerStatus status = sc.Status; c.UnInstallService("gView.MapServer.Tasker"); } catch { } if (!c.InstallService(path, "gView.MapServer.Tasker", "gView MapServer Tasker", false)) { txtOutput.Text = ServiceInstallUtil.InstallService(path); btnContinue.Visible = true; return; //lblStatus.Text = "Error on installing windows service 'gView.MapServer.Tasker'"; //btnContinue.Visible = true; //return; } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully installed..."; } else if (_action == Action.SetAutomatic) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Automatic); } else if (_action == Action.SetManual) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Manual); } else if (_action == Action.SetDisabled) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Disabled); } else if (_action == Action.Unsinstall) { try { // Service stoppen ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); TimeSpan ts = new TimeSpan(0, 0, 30); sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped, ts); } catch { } if (!c.UnInstallService("gView.MapServer.Tasker")) { txtOutput.Text = "Error on uninstalling windows service 'gView.MapServer.Tasker'"; btnContinue.Visible = true; return; } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully uninstalled..."; } else if (_action == Action.Start) { try { TimeSpan ts = new TimeSpan(0, 0, 30); ServiceController sc = new ServiceController("gView.MapServer.Tasker"); if (sc.Status != ServiceControllerStatus.Running) { sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running, ts); } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully started..."; } catch (Exception ex) { txtOutput.Text = "Error: " + ex.Message; btnContinue.Visible = true; return; } } else if (_action == Action.Stop) { try { TimeSpan ts = new TimeSpan(0, 0, 30); ServiceController sc = new ServiceController("gView.MapServer.Tasker"); if (sc.Status != ServiceControllerStatus.Stopped) { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped, ts); } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully stopped..."; } catch (Exception ex) { txtOutput.Text = "Error: " + ex.Message; btnContinue.Visible = true; return; } } } _succeeded = true; this.Refresh(); Thread.Sleep(2000); this.Close(); }