/// <summary> /// OnSelectionAction method handles the execution of a selection-dependent action. /// </summary> /// <param name="action">The executed action.</param> /// <param name="status">The object that holds the status information.</param> protected override void OnSelectionAction(Action action, AsyncStatus status) { ManagementObjectSearcher ServiceQuery = new ManagementObjectSearcher ("Select * from Win32_Service Where DisplayName = '" + SelectedNodes[0].DisplayName + "'"); string actionString = action.Tag as string; if (actionString != null) { switch (actionString) { case "Start": { foreach (ManagementObject ServiceObject in ServiceQuery.Get()) { ServiceObject.InvokeMethod("StartService", null); } SelectedNodes[0].SubItemDisplayNames[1] = "Started"; ((Action)SelectionData.ActionsPaneItems[0]).Enabled = false; ((Action)SelectionData.ActionsPaneItems[3]).Enabled = false; } break; case "Stop": { foreach (ManagementObject ServiceObject in ServiceQuery.Get()) { ServiceObject.InvokeMethod("StopService", null); } SelectedNodes[0].SubItemDisplayNames[1] = "Stopped"; ((Action)SelectionData.ActionsPaneItems[1]).Enabled = false; ((Action)SelectionData.ActionsPaneItems[2]).Enabled = false; ((Action)SelectionData.ActionsPaneItems[3]).Enabled = false; } break; case "Pause": { foreach (ManagementObject ServiceObject in ServiceQuery.Get()) { ServiceObject.InvokeMethod("PauseService", null); } SelectedNodes[0].SubItemDisplayNames[1] = "Paused"; ((Action)SelectionData.ActionsPaneItems[0]).Enabled = false; ((Action)SelectionData.ActionsPaneItems[2]).Enabled = false; } break; case "Resume": { foreach (ManagementObject ServiceObject in ServiceQuery.Get()) { ServiceObject.InvokeMethod("ResumeService", null); } SelectedNodes[0].SubItemDisplayNames[1] = "Started"; ((Action)SelectionData.ActionsPaneItems[0]).Enabled = false; ((Action)SelectionData.ActionsPaneItems[3]).Enabled = false; } break; case "Properties": { SelectionData.ShowPropertySheet("Service Properties"); } break; } } }