Added catch block for ManagementException

Related to issue #925
This commit is contained in:
Travis Nickles 2019-12-26 21:30:47 -06:00
parent a4936eb5a0
commit b6b57ed7ca

View File

@ -257,9 +257,11 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question
autoProfileHolder.AutoProfileColl.CollectionChanged += AutoProfileColl_CollectionChanged; autoProfileHolder.AutoProfileColl.CollectionChanged += AutoProfileColl_CollectionChanged;
//autoProfControl.AutoProfVM.AutoProfileSystemChange += AutoProfVM_AutoProfileSystemChange; //autoProfControl.AutoProfVM.AutoProfileSystemChange += AutoProfVM_AutoProfileSystemChange;
bool wmiConnected = false;
WqlEventQuery q = new WqlEventQuery(); WqlEventQuery q = new WqlEventQuery();
ManagementScope scope = new ManagementScope("root\\CIMV2"); ManagementScope scope = new ManagementScope("root\\CIMV2");
q.EventClassName = "Win32_PowerManagementEvent"; q.EventClassName = "Win32_PowerManagementEvent";
try try
{ {
scope.Connect(); scope.Connect();
@ -268,13 +270,20 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question
if (scope.IsConnected) if (scope.IsConnected)
{ {
wmiConnected = true;
managementEvWatcher = new ManagementEventWatcher(scope, q); managementEvWatcher = new ManagementEventWatcher(scope, q);
managementEvWatcher.EventArrived += PowerEventArrive; 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);
} }
} }