private void TcRegistry_OnTelemetryChanging(object sender, TelemetryControl.TelemetryEventArgs e)
        {
            var telemetry = (TelemetryRegistryKey)e.Telemetry;

            if (e.Enabled)
            {
                var result = NvidiaController.EnableTelemetryRegistryItem(telemetry);

                if (result.Error != null)
                {
                    e.Cancel = true;
                    CustomMessageBox.Show(
                        Properties.Resources.Failed_to_enable_registry_item,
                        Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Logging.GetFileLogger().Log(Level.Info, result.Error != null
                    ? $"{Properties.Resources.Failed_to_enable_registry_item}: {result.Item.Name}"
                    : $"{Properties.Resources.Registry_item_enabled}: {result.Item.Name}");
            }

            else
            {
                var result = NvidiaController.DisableTelemetryRegistryItem(telemetry);

                if (result.Error != null)
                {
                    e.Cancel = true;
                    CustomMessageBox.Show(
                        Properties.Resources.Failed_to_disable_registry_item,
                        Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Logging.GetFileLogger().Log(Level.Info, result.Error != null
                    ? $"{Properties.Resources.Failed_to_disable_registry_item}: {result.Item.Name}"
                    : $"{Properties.Resources.Registry_item_disabled}: {result.Item.Name}");
            }
        }
        private static void SilentlyDisableTelemetry()
        {
            Logging.GetFileLogger().Log(Level.Info, DisableNvidiaTelemetry.Properties.Resources.Silently_disabling_telemetry_services);

            foreach (var serviceResult in NvidiaController.EnumerateTelemetryServices().ToList())
            {
                if (serviceResult.Error == null)
                {
                    var startupResult = NvidiaController.DisableTelemetryServiceStartup(serviceResult.Item);
                    Logging.GetFileLogger().Log(Level.Info, startupResult.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Disable_service_startup_failed}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Automatic_service_startup_disabled}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})");
                    Logging.GetEventLogger().Log(Level.Info, startupResult.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Disable_service_startup_failed}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Automatic_service_startup_disabled}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})");

                    var result = NvidiaController.DisableTelemetryService(serviceResult.Item);
                    Logging.GetFileLogger().Log(Level.Info, result.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Failed_to_stop_service}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Service_stopped}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})");
                    Logging.GetEventLogger().Log(Level.Info, result.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Failed_to_stop_service}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Service_stopped}: {serviceResult.Item.Service.DisplayName} ({serviceResult.Item.Service.ServiceName})");
                }
            }

            Logging.GetFileLogger().Log(Level.Info, DisableNvidiaTelemetry.Properties.Resources.Silently_disabling_telemetry_tasks);

            foreach (var taskResult in NvidiaController.EnumerateTelemetryTasks().ToList())
            {
                if (taskResult.Error == null)
                {
                    var result = NvidiaController.DisableTelemetryTask(taskResult.Item);

                    Logging.GetFileLogger().Log(Level.Info, result.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Failed_to_disable_task}: {result.Item.Task.Path}"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Task_disabled}: {result.Item.Task.Path}");
                    Logging.GetEventLogger().Log(Level.Info, result.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Failed_to_disable_task}: {result.Item.Task.Path}"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Task_disabled}: {result.Item.Task.Path}");
                }

                else
                {
                    Logging.GetFileLogger().Log(Level.Error, taskResult.Error);
                    Logging.GetEventLogger().Log(Level.Error, taskResult.Error);
                }
            }

            Logging.GetFileLogger().Log(Level.Info, DisableNvidiaTelemetry.Properties.Resources.Silently_disabling_telemetry_registry_items);

            foreach (var registryResult in NvidiaController.EnumerateTelemetryRegistryItems().ToList())
            {
                if (registryResult.Error == null)
                {
                    var result = NvidiaController.DisableTelemetryRegistryItem(registryResult.Item);

                    Logging.GetFileLogger().Log(Level.Info, result.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Failed_to_disable_registry_item}: {result.Item.Name}"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Registry_item_disabled}: {result.Item.Name}");
                    Logging.GetEventLogger().Log(Level.Info, result.Error != null
                        ? $"{DisableNvidiaTelemetry.Properties.Resources.Failed_to_disable_registry_item}: {result.Item.Name}"
                        : $"{DisableNvidiaTelemetry.Properties.Resources.Registry_item_disabled}: {result.Item.Name}");
                }
            }
        }