Check time of last shutdown?
Check time of last shutdown?
Is there a way to get the time (and day) of the last time the computer was shutdown into Purebasic?
Re: Check time of last shutdown?
Both of those seem to return time since startup. I am looking for time since last shutdown - Herunterfahren.RSBasic wrote: Sun Jan 28, 2024 7:39 pm https://www.rsbasic.de/aktualisierung/w ... mitteln.pb
https://www.rsbasic.de/aktualisierung/w ... eln%202.pb
Re: Check time of last shutdown?
With wevtutil to retrieve information about event logs
Code: Select all
Params$ = "qe System " +#DQUOTE$+ "/q:*[System [(EventID=1074)]]" +#DQUOTE$+ " /rd:true /f:text /c:1"
Program = RunProgram("wevtutil", Params$, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
If Program
While ProgramRunning(Program)
If AvailableProgramOutput(Program)
Output$ = ReadProgramString(Program) ; Date: 2024-01-26T14:31:15.5170000Z
If Left(Output$, 7) = " Date:"
LastShudown$ = Mid(Output$, 9, 19) ; LastShudown$ = Left(StringField(Output$, 2, "Date: "), 19)
;Debug LastShudown$
LastShudown = ParseDate("%yyyy-%mm-%ddT%hh:%ii:%ss", LastShudown$)
Debug FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss", LastShudown)
EndIf
EndIf
Wend
CloseProgram(Program)
EndIf
Re: Check time of last shutdown?
Thanks, I had actually just been trying that myself but mines wouldn't work.
What is wrong with this:
Edit: I hadn't included the folder string.
What is wrong with this:
Code: Select all
Global f.s="/k "+"wevtutil qe system " + Chr(34) + "/q:*[System [(EventID=1074)]]" +Chr(34) +" /rd:true /f:text /c:1 | findstr /i "+Chr(34)+ "date"+Chr(34)
Debug f
RunProgram("cmd", f, #PB_Program_Read)