Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
 public void SetSuspendState(bool hibernate)
 {
     PowerManagementInterop.SetSuspendState(hibernate, false, false);
 }