private void stopAgentToolStripMenuItem_Click(object sender, EventArgs e) { MeshAgent.StopService(); connectionTimer.Enabled = false; connectionTimer.Interval = 500; timerSlowDown = 20; connectionTimer.Enabled = true; }
public void UpdateServiceStatus() { try { ServiceControllerStatus status = MeshAgent.GetServiceStatus(); startAgentToolStripMenuItem.Enabled = (status == ServiceControllerStatus.Stopped); stopAgentToolStripMenuItem.Enabled = (status != ServiceControllerStatus.Stopped); if (agent.State != 0) { return; } pictureBox1.Visible = false; // Green pictureBox2.Visible = true; // Red pictureBox3.Visible = false; // Yellow pictureBox4.Visible = false; // Help switch (status) { case ServiceControllerStatus.ContinuePending: { stateLabel.Text = "Agent is continue pending"; break; } case ServiceControllerStatus.Paused: { stateLabel.Text = "Agent is paused"; break; } case ServiceControllerStatus.PausePending: { stateLabel.Text = "Agent is pause pending"; break; } case ServiceControllerStatus.Running: { stateLabel.Text = "Agent is running"; break; } case ServiceControllerStatus.StartPending: { stateLabel.Text = "Agent is start pending"; break; } case ServiceControllerStatus.Stopped: { stateLabel.Text = "Agent is stopped"; break; } case ServiceControllerStatus.StopPending: { stateLabel.Text = "Agent is stopped pending"; break; } } } catch (Exception) { startAgentToolStripMenuItem.Enabled = false; stopAgentToolStripMenuItem.Enabled = false; stateLabel.Text = "Agent not installed"; } }
public MainForm(string[] args) { // Perform self update operations if any. this.args = args; bool startVisible = false; string update = null; string delete = null; foreach (string arg in this.args) { if ((arg.Length == 8) && (arg.ToLower() == "-visible")) { startVisible = true; } if ((arg.Length == 9) && (arg.ToLower() == "-noupdate")) { noUpdate = true; } if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-update:") { update = arg.Substring(8); } if (arg.Length > 8 && arg.Substring(0, 8).ToLower() == "-delete:") { delete = arg.Substring(8); } } if (update != null) { // New args ArrayList args2 = new ArrayList(); foreach (string a in args) { if (a.StartsWith("-update:") == false) { args2.Add(a); } } // Remove ".update.exe" and copy System.Threading.Thread.Sleep(1000); File.Copy(Assembly.GetEntryAssembly().Location, update, true); System.Threading.Thread.Sleep(1000); Process.Start(update, string.Join(" ", (string[])args2.ToArray(typeof(string))) + " -delete:" + Assembly.GetEntryAssembly().Location); this.forceExit = true; Application.Exit(); return; } if (delete != null) { try { System.Threading.Thread.Sleep(1000); File.Delete(delete); } catch (Exception) { } } // Set TLS 1.2 ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; InitializeComponent(); agent = new MeshAgent("MeshCentralAssistant"); agent.onStateChanged += Agent_onStateChanged; agent.onQueryResult += Agent_onQueryResult; agent.onSessionChanged += Agent_onSessionChanged; agent.onAmtState += Agent_onAmtState; agent.onSelfUpdate += Agent_onSelfUpdate; agent.onCancelHelp += Agent_onCancelHelp; agent.onConsoleMessage += Agent_onConsoleMessage; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height); agent.ConnectPipe(); UpdateServiceStatus(); pictureBox1.Visible = false; pictureBox2.Visible = false; pictureBox3.Visible = true; isAdministrator = IsAdministrator(); if (isAdministrator) { startAgentToolStripMenuItem.Visible = true; stopAgentToolStripMenuItem.Visible = true; toolStripMenuItem2.Visible = true; } else { startAgentToolStripMenuItem.Visible = false; stopAgentToolStripMenuItem.Visible = false; toolStripMenuItem2.Visible = false; } if (startVisible) { mainNotifyIcon_MouseClick(this, null); } }