Ejemplo n.º 1
0
 public uint CallNtPowerInformation(int InformationLevel, IntPtr lpInputBuffer, int nInputBufferSize, long lpOutputBuffer,
                                    int nOutputBufferSize)
 {
     return(PowerManagerInterop.CallNtPowerInformation(InformationLevel, lpInputBuffer, nInputBufferSize,
                                                       lpOutputBuffer,
                                                       nOutputBufferSize));
 }
Ejemplo n.º 2
0
        public static Int64 GetLastWakeTime()
        {
            IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Int64)));

            PowerManagerInterop.CallNtPowerInformation(SleepWakeTimeManager.LastWakeTime, IntPtr.Zero, 0, buffer.ToInt64(), Marshal.SizeOf(typeof(Int64)));

            return(buffer.ToInt64());
        }
Ejemplo n.º 3
0
        public static bool ManageHybernateFile(bool isHybernateFileReserved)
        {
            IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(bool)));

            Marshal.WriteInt32(buffer, 0, Convert.ToInt32(isHybernateFileReserved));
            bool resultState = false;

            PowerManagerInterop.CallNtPowerInformation(SystemReserveHiberFile, buffer, 0, resultState, Marshal.SizeOf(typeof(bool)));
            return(resultState);
        }
Ejemplo n.º 4
0
        public static byte[] GetSystemPowerInformation()
        {
            IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(PowerManagerInterop.SYSTEM_POWER_LEVEL)));
            uint   result = PowerManagerInterop.CallNtPowerInformation(SystemPowerInformation, IntPtr.Zero, 0, buffer, Marshal.SizeOf(typeof(PowerManagerInterop.SYSTEM_POWER_LEVEL)));

            if (result == STATUS_SUCCESS)
            {
                PowerManagerInterop.SYSTEM_POWER_LEVEL powerInfo = (PowerManagerInterop.SYSTEM_POWER_LEVEL)Marshal.PtrToStructure(buffer, typeof(PowerManagerInterop.SYSTEM_POWER_LEVEL));
                return(powerInfo.Spare);
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 5
0
 public static uint GetSystemBatteryState()
 {
     PowerManagerInterop.SYSTEM_BATTERY_STATE batteryState = new PowerManagerInterop.SYSTEM_BATTERY_STATE();
     PowerManagerInterop.CallNtPowerInformation(SystemBatteryState, IntPtr.Zero, 0, batteryState, Marshal.SizeOf(typeof(PowerManagerInterop.SYSTEM_BATTERY_STATE)));
     return(batteryState.RemainingCapacity);
 }
Ejemplo n.º 6
0
 public static bool Sleep()
 {
     return(PowerManagerInterop.SetSuspendState(false, false, false));
 }
Ejemplo n.º 7
0
 public bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent)
 {
     return(PowerManagerInterop.SetSuspendState(hibernate, forceCritical, disableWakeEvent));
 }