private void RefreshTelemetryRegistry(bool logging)
        {
            var keys = new List <TelemetryRegistryKey>();

            foreach (var result in NvidiaController.EnumerateTelemetryRegistryItems())
            {
                if (logging)
                {
                    Logging.GetFileLogger().Log(Level.Info, result.Error != null
                        ? $"{Properties.Resources.Failed_to_find_registry_item}: {result.Name}"
                        : $"{Properties.Resources.Found_registry_item}: {result.Item.Name}");
                }

                if (result.Error == null)
                {
                    if (logging)
                    {
                        Logging.GetFileLogger().Log(Level.Info, $"{Properties.Resources.Registry_item_is}: {Properties.Resources.Enabled}");
                    }

                    var key = result.Item;

                    var sb = new StringBuilder();

                    sb.AppendLine(key.Name);

                    foreach (var vd in key.GetValues())
                    {
                        sb.Append("@=\"");
                        sb.Append(vd.Key);
                        sb.Append("\"");
                        sb.AppendLine();
                    }

                    tcRegistry.AddTelemetryItem(key, sb.ToString());
                    keys.Add(key);
                }
            }

            _telemetryKeys = keys;
        }
        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}");
                }
            }
        }