Exemple #1
0
 private void ShowProperty(PowerDevice device)
 {
     if (device != null)
     {
         DeviceUtility.ShowProperty(device);
     }
 }
Exemple #2
0
        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);
        }
Exemple #3
0
 public static void ShowProperty(PowerDevice device)
 {
     Process.Start("Rundll32", $@"devmgr.dll,DeviceProperties_RunDLL /DeviceID ""{device.DeviceID}""");
 }
Exemple #4
0
 public async static Task <bool> SetDeviceStateAsync(PowerDevice device, bool value)
 {
     return(await Task.Run(() => SetDeviceState(device, value)));
 }
Exemple #5
0
 public static bool SetDeviceState(PowerDevice device, bool value)
 {
     return(PowerManagement.DevicePowerSetDeviceState(device.Name, value ? SetFlags.DEVICEPOWER_SET_WAKEENABLED : SetFlags.DEVICEPOWER_CLEAR_WAKEENABLED, IntPtr.Zero) == 0);
 }