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);
        }
        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);
        }
Esempio 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);
        }
        /// <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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
        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);
        }