Page 1 of 1
Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 11:39 am
by Little John
Hi all!
For instance the tool
TurnedOnTimesView by NirSoft provides detailed information about time ranges when a computer was turned on. It does do so by reading the system event log.
How can I get this information with a PureBasic program? I only want to get say the last 3 times when my local PC was turned on.
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 12:08 pm
by mk-soft
Only Window ...
MSDN
https://docs.microsoft.com/en-us/window ... ttickcount
https://docs.microsoft.com/en-us/window ... ickcount64
Code: Select all
Import "" ; Kernel32.lib
GetTickCount64()
EndImport
;cnt.i = (GetTickCount_() / 1000) & $FFFFFFFF
cnt.q = (GetTickCount64() / 1000)
days = cnt / 86400
cnt = cnt % 86400
hours = cnt / 3600
cnt = cnt % 3600
minutes = cnt / 60
cnt = cnt % 60
seconds = cnt
Debug "" + days + "d " + hours + "h " + minutes + "m " + seconds + "s "
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 12:12 pm
by BarryG
Little John wrote:How can I get this information with a PureBasic program?
We need someone to update this ->
https://www.purebasic.fr/english/viewto ... 69#p552969 Then we can parse it for the last 3 power on/off times.
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 1:00 pm
by Little John
Yes, currently I need only a solution on Windows ( that's why I posted this question in the "Windows" subforum.

)
However, GetTickCount_() does not provide the information I am looking for.
That seems to put me on the right track, thank you!
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 1:25 pm
by mk-soft
Code: Select all
Import "" ; Kernel32.lib
GetTickCount64()
EndImport
;cnt.i = (GetTickCount_() / 1000) & $FFFFFFFF
cnt.q = (GetTickCount64() / 1000)
TurnOn = Date() - (GetTickCount64() / 1000)
Debug FormatDate("Computer turn on: %YYYY-%MM-%DD %HH:%II:%SS", TurnOn)
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 1:37 pm
by Little John
mk-soft wrote:Code: Select all
Import "" ; Kernel32.lib
GetTickCount64()
EndImport
;cnt.i = (GetTickCount_() / 1000) & $FFFFFFFF
cnt.q = (GetTickCount64() / 1000)
TurnOn = Date() - (GetTickCount64() / 1000)
Debug FormatDate("Computer turn on: %YYYY-%MM-%DD %HH:%II:%SS", TurnOn)
*Sigh*
Please read before "replying"!
Little John wrote:However, GetTickCount_() does not provide the information I am looking for.
If you want to know what I am looking for, read my first post in this thread thoroughly.
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 3:11 pm
by mk-soft
Sorry,
I thought you wanted to know when the computer was started and then filter the data from date and time.
But I still find my code very helpful

Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 4:07 pm
by Everything
-TurnedOnTimesView based on a few types of events on the event log of Windows
-If you clear your system event log, TurnedOnTimesView will not be able to detect the shutdown/startup times
-On systems prior to Windows Vista, Shutdown Reason, Shutdown Type, and Shutdown Process fields are usually empty
TurnedOnTimesView uses the following events to determine the turn off/turn on times:
EventID 41 (Microsoft-Windows-Kernel-Power): The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.
EventID 42 (Microsoft-Windows-Kernel-Power): The system is entering sleep
EventID 1 (Microsoft-Windows-Power-Troubleshooter): The system has resumed from sleep.
EventID 1074 (USER32): The process xxx has initiated the xxx of computer xxx on behalf of user xxx for the following reason: xxx
EventID 6005 (EventLog): The Event log service was started.
EventID 6006 (EventLog): The Event log service was stopped
Windows event logs with PB
Re: Times at which a local computer was turned on
Posted: Wed Apr 22, 2020 5:40 pm
by Little John
mk-soft wrote:But I still find my code very helpful

I am glad that I was able to give you the opportunity to post offtopic blah blah and feel helpful.
Re: Times at which a local computer was turned on
Posted: Thu Apr 23, 2020 8:15 am
by dige
mk-soft wrote:Sorry,
I thought you wanted to know when the computer was started and then filter the data from date and time.
But I still find my code very helpful

@mk-soft: Since Windows only restarts on reboot, your value shows the time of the last reboot.