Page 1 of 1

Check time of last shutdown?

Posted: Sun Jan 28, 2024 6:56 pm
by matalog
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?

Posted: Sun Jan 28, 2024 7:39 pm
by RSBasic

Re: Check time of last shutdown?

Posted: Sun Jan 28, 2024 9:01 pm
by matalog
Both of those seem to return time since startup. I am looking for time since last shutdown - Herunterfahren.

Re: Check time of last shutdown?

Posted: Sun Jan 28, 2024 10:03 pm
by ChrisR
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?

Posted: Sun Jan 28, 2024 10:19 pm
by matalog
Thanks, I had actually just been trying that myself but mines wouldn't work.

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)
Edit: I hadn't included the folder string.