Check time of last shutdown?

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Check time of last shutdown?

Post by matalog »

Is there a way to get the time (and day) of the last time the computer was shutdown into Purebasic?
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Check time of last shutdown?

Post by matalog »

Both of those seem to return time since startup. I am looking for time since last shutdown - Herunterfahren.
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Check time of last shutdown?

Post 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
User avatar
matalog
Enthusiast
Enthusiast
Posts: 304
Joined: Tue Sep 05, 2017 10:07 am

Re: Check time of last shutdown?

Post 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.
Post Reply