public BattaryState GetSystemBatteryState() { IntPtr state = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(BattaryState))); int ntStatus = PowerManagementInterop.CallNtPowerInformation( 5, IntPtr.Zero, 0, state, (UInt32)Marshal.SizeOf(typeof(BattaryState)) ); return((BattaryState)Marshal.PtrToStructure(state, typeof(BattaryState))); }
public PowerInformaion GetSystemPowerInformation() { IntPtr state = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(PowerInformaion))); int ntStatus = PowerManagementInterop.CallNtPowerInformation( 12, IntPtr.Zero, 0, state, (UInt32)Marshal.SizeOf(typeof(PowerInformaion)) ); return((PowerInformaion)Marshal.PtrToStructure(state, typeof(PowerInformaion))); }
public string GetLastWakeTime() { IntPtr lastWake = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(long))); int ntStatus = PowerManagementInterop.CallNtPowerInformation( 14, IntPtr.Zero, 0, lastWake, (uint)Marshal.SizeOf(typeof(long)) ); long lastWakeTimeInSeconds = Marshal.ReadInt64(lastWake, 0) / 10000000; TimeSpan time = TimeSpan.FromSeconds(lastWakeTimeInSeconds); return(DateTime.Today.Add(time).ToString()); }
public void SetSuspendState(bool hibernate) { PowerManagementInterop.SetSuspendState(hibernate, false, false); }