Ejemplo n.º 1
0
        public static void ShowSystemPowerInformation()
        {
            SystemPowerInformation state = new SystemPowerInformation();
            var ptr = IntPtr.Zero;

            try
            {
                ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemPowerInformation)));
                uint retval = CallNtPowerInformation(
                    SYSTEM_POWER_INFORMATION_LEVEL,
                    IntPtr.Zero,
                    0,
                    ptr,
                    Marshal.SizeOf(typeof(SystemPowerInformation))
                    );

                if (retval == STATUS_SUCCESS)
                {
                    state = Marshal.PtrToStructure <SystemPowerInformation>(ptr);
                }
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptr);
                }
            }

            ShowAllPowerInfo(state);
        }
 public static extern uint CallNtPowerInformation(
     int InformationLevel,
     IntPtr lpInputBuffer,
     int nInputBufferSize,
     out SystemPowerInformation spi,
     int nOutputBufferSize
     );
Ejemplo n.º 3
0
        public SystemPowerInformation GetSystemPowerInformation()
        {
            IntPtr systemBatteryStatePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(SystemPowerInformation)));
            int    status = CallNtPowerInformation(SystemPowerInformation, IntPtr.Zero, 0, systemBatteryStatePtr,
                                                   Marshal.SizeOf(typeof(SystemPowerInformation)));
            SystemPowerInformation spInformation = (SystemPowerInformation)Marshal.PtrToStructure(systemBatteryStatePtr, typeof(SystemPowerInformation));

            Marshal.FreeHGlobal(systemBatteryStatePtr);
            return(spInformation);
        }
Ejemplo n.º 4
0
 internal static extern uint CallNtPowerInformation(PowerInformationLevel informationLevel,
                                                    IntPtr inputBuffer, int inputBufferSize,
                                                    out SystemPowerInformation outputBuffer, int outputBufferSize);
 public static extern PowerInformationStatus CallNtPowerInformation(
     PowerInformationLevel informationLevel,
     IntPtr inputBuffer,
     int inputBufferSize,
     out SystemPowerInformation systemBatteryState,
     int outputBufferSize);
 private static extern NtStatus CallNtPowerInformation(
     PowerInformationLevel informationLevel, 
     IntPtr inputBuffer, 
     int inputBufferSize, 
     out SystemPowerInformation outputBuffer, 
     int outputBufferSize);