public static IReadOnlyList <PowerDevice> GetPowerDevices() { var result = new List <PowerDevice>(); if (PowerManagement.DevicePowerOpen(0)) { var wakeEnabledDevices = GetWakeEnabledDevices(); var wakeProgrammableDevices = GetWakeProgrammableDevices(); var signedDrivers = DriverUtility.GetSignedDrivers(); try { uint index = 0; string lastDevice = null; while (TryGetDevice(index, out lastDevice)) { var driver = signedDrivers.Where(x => x.HardWareID == lastDevice).FirstOrDefault(); if (driver != null) { TryGetDevice(index, out string name, flagsAllName); var powerDevice = new PowerDevice { ClassGuid = driver.ClassGuid, Description = driver.Description, DeviceID = driver.DeviceID, DeviceName = driver.DeviceName, FriendlyName = driver.FriendlyName, HardWareID = driver.HardWareID, IsWakeEnabled = wakeEnabledDevices.Contains(driver.HardWareID), IsWakeProgrammable = wakeProgrammableDevices.Contains(name), Location = driver.Location, Manufacturer = driver.Manufacturer, Name = name }; result.Add(powerDevice); } index++; } } finally { PowerManagement.DevicePowerClose(); } } return(result); }
private static IReadOnlyList <string> GetWakeEnabledDevices() { var result = new List <string>(); if (PowerManagement.DevicePowerOpen(0)) { try { uint index = 0; string lastDevice = null; while (TryGetDevice(index, out lastDevice, flagsWakeEnabled)) { result.Add(lastDevice); index++; } } finally { PowerManagement.DevicePowerClose(); } } return(result); }