diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 3c4ff38..8c6d7fc 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -7,7 +7,8 @@ using System.Media; using System.Threading.Tasks; using static DS4Windows.Global; using System.Threading; -using Registry = Microsoft.Win32.Registry; +using System.Diagnostics; +using Microsoft.Win32; namespace DS4Windows { @@ -83,7 +84,32 @@ namespace DS4Windows } } - public void createHidGuardKey() + public void ScanPurgeHidGuard() + { + RegistryKey tempkey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist"); + string[] subkeys = tempkey.GetSubKeyNames(); + bool processExists = false; + for (int ind = 0, arlen = subkeys.Length; ind < arlen; ind++) + { + processExists = true; + try + { + Process.GetProcessById(Convert.ToInt32(subkeys[ind])); + } + catch { processExists = false; } + + if (!processExists) + { + try + { + Registry.LocalMachine.DeleteSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist\" + subkeys[ind]); + } + catch { } + } + } + } + + public void CreateHidGuardKey() { try { diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 25359e5..5bbd95e 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -2463,7 +2463,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question { Registry.LocalMachine.DeleteSubKeyTree(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist"); Log.LogToGui("Cleared HidGuardian Whitelist", false); - Program.rootHub.createHidGuardKey(); + Program.rootHub.CreateHidGuardKey(); } catch { } } diff --git a/DS4Windows/Program.cs b/DS4Windows/Program.cs index 789393f..b9254bb 100644 --- a/DS4Windows/Program.cs +++ b/DS4Windows/Program.cs @@ -103,7 +103,8 @@ namespace DS4Windows //if (mutex.WaitOne(TimeSpan.Zero, true)) //{ createControlService(); - rootHub.createHidGuardKey(); + //rootHub.ScanPurgeHidGuard(); + rootHub.CreateHidGuardKey(); //rootHub = new ControlService(); Application.EnableVisualStyles(); Application.Run(new DS4Form(args));