Ejemplo n.º 1
0
        public SYSTEM_POWER_INFORMATION GetSystemPowerInformation()
        {
            SYSTEM_POWER_INFORMATION spi;

            CallPowerInformation.CallNtPowerInformation(
                12,
                IntPtr.Zero,
                0,
                out spi,
                Marshal.SizeOf(typeof(SYSTEM_POWER_INFORMATION)));

            return(spi);
        }
Ejemplo n.º 2
0
        public SYSTEM_BATTERY_STATE GetBatteryState()
        {
            SYSTEM_BATTERY_STATE sbs;

            CallPowerInformation.CallNtPowerInformation(
                5,
                IntPtr.Zero,
                0,
                out sbs,
                Marshal.SizeOf(typeof(SYSTEM_BATTERY_STATE)));

            return(sbs);
        }
Ejemplo n.º 3
0
        public uint ReserveHyberFile()
        {
            int size  = Marshal.SizeOf(typeof(byte));
            var pBool = Marshal.AllocHGlobal(size);

            Marshal.WriteByte(pBool, 0, 1);  // last parameter 0 (FALSE), 1 (TRUE)

            uint retval = CallPowerInformation.CallNtPowerInformation(
                10,
                pBool,
                0,
                out pBool,
                size);

            Marshal.FreeHGlobal(pBool);
            return(retval);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The get last wake time.
        /// </summary>
        /// <returns>
        /// returns time interval in 100-nanosecond units, at the last system wake time
        /// </returns>
        public double GetLastWakeTime()
        {
            ulong retvalue;

            uint callsuccess = CallPowerInformation.CallNtPowerInformation(
                14,
                IntPtr.Zero,
                0,
                out retvalue,
                Marshal.SizeOf(typeof(ulong)));

            if (callsuccess == StatusSuccess)
            {
                return((double)retvalue); // VBA only supports Double
            }

            return(0);
        }
Ejemplo n.º 5
0
        public ulong?GetLastWakeTime()
        {
            uint  statusSuccess = 0;
            ulong retvalue;
            uint  callsuccess = CallPowerInformation.CallNtPowerInformation(
                14,
                IntPtr.Zero,
                0,
                out retvalue,
                Marshal.SizeOf(typeof(ulong)));

            if (callsuccess == statusSuccess)
            {
                return(retvalue);
            }

            return(null);
        }
Ejemplo n.º 6
0
        public SYSTEM_POWER_INFORMATION?GetSystemPowerInformation()
        {
            uint statusSuccess = 0;
            SYSTEM_POWER_INFORMATION spi;

            uint retval = CallPowerInformation.CallNtPowerInformation(
                12,
                IntPtr.Zero,
                0,
                out spi,
                Marshal.SizeOf(typeof(SYSTEM_POWER_INFORMATION)));

            if (retval == statusSuccess)
            {
                return(spi);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public SYSTEM_BATTERY_STATE?GetBatteryState()
        {
            uint statusSuccess = 0;
            SYSTEM_BATTERY_STATE sbs;

            uint retval = CallPowerInformation.CallNtPowerInformation(
                5,
                IntPtr.Zero,
                0,
                out sbs,
                Marshal.SizeOf(typeof(SYSTEM_BATTERY_STATE)));

            if (retval == statusSuccess)
            {
                return(sbs);
            }

            return(null);
        }
Ejemplo n.º 8
0
        public bool FreeHybernatoinFile()
        {
            int size  = Marshal.SizeOf(typeof(byte));
            var pBool = Marshal.AllocHGlobal(size);

            Marshal.WriteByte(pBool, 0, 0);  // last parameter 0 (FALSE), 1 (TRUE)

            uint retval = CallPowerInformation.CallNtPowerInformation(
                10,
                pBool,
                Marshal.SizeOf(typeof(bool)),
                out pBool,
                0);

            Marshal.FreeHGlobal(pBool);
            if (retval == StatusSuccess)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
 public void SetSleepState()
 {
     CallPowerInformation.SetSuspendState(false, false, false);
 }