public SystemPowerInformation GetSystemPowerInformation() { IntPtr status = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemPowerInformation))); Win32FunctionInvokeWrapper.CallNtPowerInformation(INFORMATION_LEVEL.SystemPowerInformation, IntPtr.Zero, 0, status, (UInt32)Marshal.SizeOf(typeof(SystemPowerInformation))); return((SystemPowerInformation)Marshal.PtrToStructure(status, typeof(SystemPowerInformation))); }
public DateTime GetLastSleepTime() { IntPtr status = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(long))); Win32FunctionInvokeWrapper.CallNtPowerInformation(INFORMATION_LEVEL.LastSleepTime, (IntPtr)null, 0, status, (UInt32)Marshal.SizeOf(typeof(long))); long lastSleepTime = (long)Marshal.PtrToStructure(status, typeof(long)); return(DateTime.FromFileTime(lastSleepTime)); }