![]() |
Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
Hallo,
GetTickCount liefert mir ja die Millisekunden seit dem letzten Windows Systemstart, nun kann es aber vorkommen, dass Windows während der Laufzeit in den Suspend-Modus wechselt/versetzt wird und dann durch Tastendruck wieder aufgeweckt wird. Wie könnte ich denn diese Laufzeit seit dem Aufwachen aus dem Suspend-Modus feststellen? GetTickCount wird dadurch ja nicht zurückgesetzt und liefert mir nachwievor die Zeit, seit dem Windows das erste Mal gestartet wurde... |
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
Du kannst den Event aus dem Eventlog auslesen und den Zeitstempel Ermitteln. Entweder über WMI oder direkt über ReadEventLog.
|
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
![]() Sorry, Code gerade getestet: Zeigt nur SystemBootUpTime. |
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
Das gibt Dir auch nur die Zeit seit dem letzten Systemstart. Über das Eventlog (z.b. mit wevutil) erhält man folgende Infos:
Code:
Event[0]:
Log Name: System Source: Microsoft-Windows-Power-Troubleshooter Date: 2015-07-03T15:55:37.150 Event ID: 1 Task: N/A Level: Informationen Opcode: Info Keyword: N/A User: S-1-5-19 User Name: NT-AUTORITÄT\LOKALER DIENST Computer: xxx.xxx.xxx.lu Description: Das System wurde aus dem Energiesparmodus reaktiviert. Zeit im Energiesparmodus: ?2015?-?07?-?03T13:43:35.320717800Z Reaktivierungszeit: ?2015?-?07?-?03T13:55:26.348048500Z Reaktivierungsquelle: Gerät -USB-Root-Hub |
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
![]()
Delphi-Quellcode:
an.
LastWakeTime
Delphi scheint (mal wieder) dafür keine Header zu haben, mit dem CPP Builder geht's aber:
Code:
#include <iostream>
#include <windows.h> #include <PowrProf.h> #include <ntstatus.h> #include <System.SysUtils.hpp> #include <System.TimeSpan.hpp> int _tmain(int argc, _TCHAR* argv[]) { POWER_INFORMATION_LEVEL infoLevel = POWER_INFORMATION_LEVEL::LastWakeTime; PULONGLONG lastSleepTime = new ULONGLONG(); if( STATUS_SUCCESS != CallNtPowerInformation(infoLevel, NULL, 0, lastSleepTime, sizeof(ULONGLONG)) ) System::Sysutils::RaiseLastOSError(); __int64 msWakeCount = *lastSleepTime / 10 / 1000; std::cout << "Last wake ms count:"<< msWakeCount << "\n"; std::cout << "GetTickCount64(): " << GetTickCount64() << "\n"; double msDifference = GetTickCount64() - msWakeCount; TTimeSpan timeSpan = TTimeSpan::FromMilliseconds(msDifference); std::cout << "System wurde ausgeweckt vor " << timeSpan.Hours << " Stunden, " << timeSpan.Minutes << " Minuten und " << timeSpan.Seconds << " Sekunden."; std::getchar(); return 0; } |
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
Delphi-Quellcode:
POWER_INFORMATION_LEVEL = (AdministratorPowerPolicy, LastSleepTime, LastWakeTime,
ProcessorInformation, ProcessorPowerPolicyAc, ProcessorPowerPolicyCurrent, ProcessorPowerPolicyDc, SystemBatteryState, SystemExecutionState, SystemPowerCapabilities, SystemPowerInformation, SystemPowerPolicyAc, SystemPowerPolicyCurrent, SystemPowerPolicyDc, SystemReserveHiberFile, VerifyProcessorPowerPolicyAc, VerifyProcessorPowerPolicyDc, VerifySystemPolicyAc, VerifySystemPolicyDc); ![]() |
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
Erstmal vielen Dank für den Tipp. Irgendwie scheine ich mit CallNtPowerInformation allerdings auf Kriegfuß zu stehen, folgenden Code habe ich bisher:
Delphi-Quellcode:
type
function CallNtPowerInformation(InformationLevel: DWORD; InPutBuffer: Pointer; InputBufferSize: ULONG; OutPutBuffer: Pointer; OutPutBufferSize: ULONG): DWORD; stdcall; external 'PowrProf.dll'; POWER_INFORMATION_LEVEL = (AdministratorPowerPolicy, LastSleepTime, LastWakeTime, ProcessorInformation, ProcessorPowerPolicyAc, ProcessorPowerPolicyCurrent, ProcessorPowerPolicyDc, SystemBatteryState, SystemExecutionState, SystemPowerCapabilities, SystemPowerInformation, SystemPowerPolicyAc, SystemPowerPolicyCurrent, SystemPowerPolicyDc, SystemReserveHiberFile, VerifyProcessorPowerPolicyAc, VerifyProcessorPowerPolicyDc, VerifySystemPolicyAc, VerifySystemPolicyDc); function get_time_since_last_wakeup : string; var Status : DWord; lastWakeTime : Pointer; begin Result:='unbekannt'; lastWakeTime:=nil; lastWakeTime:=AllocMem(SizeOf(POWER_INFORMATION_LEVEL)); try Status:=CallNtPowerInformation(14, nil, 0, lastWakeTime, sizeof(UINT64)); if Status = 0 {STATUS_SUCCESS} then begin {hier müsste ich irgendwie an die Aufwachzeit bzw. noch besser, die Zeitspanne seit dem letzten aufwachen herankommen} end; Finally FreeMem(lastWakeTime); end; end; |
AW: Zeit seit dem letzten Aufwachen aus dem Suspend-Modus ermitteln
Folgender Code funktioniert - ob etwas Sinnvolles heraus kommt, weiss ich nicht.
Delphi-Quellcode:
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. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz