unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
POWER_INFORMATION_LEVEL =
(SystemPowerPolicyAc,
SystemPowerPolicyDc,
VerifySystemPolicyAc,
VerifySystemPolicyDc,
SystemPowerCapabilities,
SystemBatteryState,
SystemPowerStateHandler,
ProcessorStateHandler,
SystemPowerPolicyCurrent,
AdministratorPowerPolicy,
SystemReserveHiberFile,
ProcessorInformation,
SystemPowerInformation,
ProcessorStateHandler2,
LastWakeTime,
LastSleepTime,
SystemExecutionState,
SystemPowerStateNotifyHandler,
ProcessorPowerPolicyAc,
ProcessorPowerPolicyDc,
VerifyProcessorPowerPolicyAc,
VerifyProcessorPowerPolicyDc,
ProcessorPowerPolicyCurrent,
SystemPowerStateLogging,
SystemPowerLoggingEntry);
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
type
NTSTATUS = cardinal;
const
powrprofdll = '
powrprof.dll';
function CallNtPowerInformation(InformationLevel: POWER_INFORMATION_LEVEL;
lpInputBuffer: Pointer; nInputBufferSize: cardinal; lpOutputBuffer: Pointer;
nOutputBufferSize: cardinal): NTSTATUS;
stdcall;
function CallNtPowerInformation;
external powrprofdll
Name '
CallNtPowerInformation';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var FLST: Int64;
FLWT: Int64;
begin
//100-nanosecond units, at the last system wake time
//100-nanosecond units, at the last system sleep time
CallNtPowerInformation(LastWakeTime,
nil,0,@FLWT,SizeOf(FLWT));
CallNtPowerInformation(LastSleepTime,
nil,0,@FLST,SizeOf(FLST));
//wahrscheinlich ist in den folgenden 2 Zeilen etwas falsch
FLWT:=Round(FLWT/10/1000/60/60);
// 100nsec -- 1 msec -- 1sec --1min --1h
FLST:=Round(FLST/10/1000/60/60);
// 100nsec -- 1 msec -- 1sec --1min --1h
Caption:= INTTOSTR(FLWT - FLST)+'
Stunden';
end;
end.