From b6b57ed7ca138c119d6d6f299232811923563f94 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 26 Dec 2019 21:30:47 -0600 Subject: [PATCH] Added catch block for ManagementException Related to issue #925 --- DS4Windows/DS4Forms/MainWindow.xaml.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/DS4Windows/DS4Forms/MainWindow.xaml.cs b/DS4Windows/DS4Forms/MainWindow.xaml.cs index 28b308f..ca0e5ab 100644 --- a/DS4Windows/DS4Forms/MainWindow.xaml.cs +++ b/DS4Windows/DS4Forms/MainWindow.xaml.cs @@ -257,9 +257,11 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question autoProfileHolder.AutoProfileColl.CollectionChanged += AutoProfileColl_CollectionChanged; //autoProfControl.AutoProfVM.AutoProfileSystemChange += AutoProfVM_AutoProfileSystemChange; + bool wmiConnected = false; WqlEventQuery q = new WqlEventQuery(); ManagementScope scope = new ManagementScope("root\\CIMV2"); q.EventClassName = "Win32_PowerManagementEvent"; + try { scope.Connect(); @@ -268,13 +270,20 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question if (scope.IsConnected) { + wmiConnected = true; managementEvWatcher = new ManagementEventWatcher(scope, q); managementEvWatcher.EventArrived += PowerEventArrive; - managementEvWatcher.Start(); + try + { + managementEvWatcher.Start(); + } + catch (ManagementException) { wmiConnected = false; } } - else + + if (!wmiConnected) { - AppLogger.LogToGui("Could not connect to Windows Management Instrumentation service. Suspend support not enabled.", true); + AppLogger.LogToGui(@"Could not connect to Windows Management Instrumentation service. +Suspend support not enabled.", true); } }