public SystemPowerInformation GetSystemPowerInformation() { var result = PowerManagementConfiguration.CallNtPowerInformation(PowerInformationLevel.SystemPowerInformation, IntPtr.Zero, 0, out SystemPowerInformation info, Marshal.SizeOf <SystemPowerInformation>()); return(result == PowerInformationStatus.Success ? info : throw new Win32Exception("Something went wrong.")); }
private int GetSleepOrWakeTime(PowerInformationLevel informationLevel) { var result = PowerManagementConfiguration.CallNtPowerInformation(informationLevel, IntPtr.Zero, 0, out long time, Marshal.SizeOf <long>()); var dateTime = new DateTime(2020, 4, 13, 0, 0, 0); return(result == PowerInformationStatus.Success ? dateTime.AddTicks(time / 100).Second : throw new Win32Exception("Something went wrong.")); }
/// <summary> /// Returns system battery state information or null if data wasn't found /// </summary> /// <returns></returns> public SystemBatteryState GetSystemBatteryState() { SystemBatteryState info; var action = PowerManagementConfiguration.CallNtPowerInformation( InformationLevelConstants.SYSTEM_BATTERY_STATE, IntPtr.Zero, 0, out info, Marshal.SizeOf(typeof(SystemBatteryState))); return(action == InformationLevelConstants.STATUS_SUCCESS ? info : throw new Win32Exception("oi oi oi !!!! bedaaaaaa ! ")); }
/// <summary> /// Returns system power information data or null if data wasn't found /// </summary> /// <returns></returns> public SystemPowerInformation GetSystemPowerInformation() { SystemPowerInformation info; var action = PowerManagementConfiguration.CallNtPowerInformation( InformationLevelConstants.SYSTEM_POWER_INFORMATION, IntPtr.Zero, 0, out info, Marshal.SizeOf(typeof(SystemPowerInformation))); return(action == InformationLevelConstants.STATUS_SUCCESS ? info : throw new Win32Exception("oi oi oi !!!! bedaaaaaa ! ")); }
private int GetSleepOrWakeTime(int informationLevel) { long time = 0; var action = PowerManagementConfiguration.CallNtPowerInformation( informationLevel, IntPtr.Zero, 0, out time, (uint)Marshal.SizeOf(typeof(long))); var epochTime = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc); return(action == InformationLevelConstants.STATUS_SUCCESS ? epochTime.AddTicks(time / 100).Second : throw new Win32Exception("oi oi oi !!!! bedaaaaaa ! ")); }
private bool HibernateFile(HibernateFileActions action) { var boolSize = Marshal.SizeOf <bool>(); IntPtr intPtr = Marshal.AllocCoTaskMem(boolSize); Marshal.WriteByte(intPtr, (byte)action); var result = PowerManagementConfiguration.CallNtPowerInformation(PowerInformationLevel.SystemReserveHiberFile, intPtr, boolSize, IntPtr.Zero, 0); return(result == PowerInformationStatus.Success); }
private bool HibernateFileAction(HibernateFileActions fileActions) { var intSize = Marshal.SizeOf <bool>(); IntPtr intPtr = Marshal.AllocCoTaskMem(intSize); Marshal.WriteByte(intPtr, (byte)fileActions); var retval = PowerManagementConfiguration.CallNtPowerInformation( InformationLevelConstants.SYSTEM_RESERVE_HIBER_FILE, fileActions == HibernateFileActions.Reserve, Marshal.SizeOf <bool>(), IntPtr.Zero, 0); return(retval == InformationLevelConstants.STATUS_SUCCESS); }