static extern uint CallNtPowerInformation( int InformationLevel, IntPtr lpInputBuffer, int nInputBufferSize, out SYSTEM_POWER_INFORMATION spi, int nOutputBufferSize );
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); }
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); }
private static extern int GetSystemPowerInformation(int level, IntPtr inpbuf, int inpbuflen, out SYSTEM_POWER_INFORMATION info, int outbuflen);