Exemplo n.º 1
0
 static extern uint CallNtPowerInformation(
     int InformationLevel,
     IntPtr lpInputBuffer,
     int nInputBufferSize,
     out SYSTEM_POWER_INFORMATION spi,
     int nOutputBufferSize
     );
Exemplo n.º 2
0
        public static bool GetPowerInformation(out SYSTEM_POWER_INFORMATION value)
        {
            SYSTEM_POWER_INFORMATION spi = new SYSTEM_POWER_INFORMATION();

            value = spi;

            IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(spi));

            Marshal.StructureToPtr(spi, pnt, false);

            uint retval = CallNtPowerInformation(
                SystemPowerInformation,
                IntPtr.Zero,
                0,
                pnt,
                (uint)Marshal.SizeOf(spi)
                );

            var ret = retval == STATUS_SUCCESS;

            if (ret)
            {
                spi   = Marshal.PtrToStructure <SYSTEM_POWER_INFORMATION>(pnt);
                value = spi;
            }
            return(ret);
        }
Exemplo n.º 3
0
    public static int GetIdleTimeRemaining()
    {
        var info = new SYSTEM_POWER_INFORMATION();
        int ret  = GetSystemPowerInformation(SystemPowerInformation, IntPtr.Zero, 0, out info, Marshal.SizeOf(info));

        if (ret != 0)
        {
            throw new System.ComponentModel.Win32Exception(ret);
        }
        return(info.TimeRemaining);
    }
Exemplo n.º 4
0
 private static extern int GetSystemPowerInformation(int level, IntPtr inpbuf, int inpbuflen, out SYSTEM_POWER_INFORMATION info, int outbuflen);