Reputation: 121
I'm using this python (3.5) code to check windows startup time but it gives me a different time from the time I get using the shell command "systeminfo"
Not happy with that, the python code is giving different times in itself! It started giving me 9:14:42, and right now it gives me 9:15:19, it's been adding a second to the boot time every 10 seconds or so.
I give you the code:
import datetime
import win32api
s = win32api.GetTickCount()
t = datetime.datetime.now()
st = datetime.timedelta(milliseconds=s)
bt = t-st
boot = "Boot time was around {}:{}:{}".format(bt.hour, bt.minute, bt.second)
print(boot)
I'm starting to think about calling the systeminfo command from python and just show the time it gives me.
Upvotes: 4
Views: 2292
Reputation: 3722
taken from comments and question edit
GetTickCount
does not report the startup time. To get that you should be using WMI
import datetime
import wmi
wmiob = wmi.WMI()
sdata = wmiob.Win32_PerfFormattedData_PerfOS_System()
uptime = sdata[-1].SystemUpTime
tnow = datetime.datetime.now()
utime = datetime.timedelta(seconds=int(uptime))
boot = tnow-utime
bootime = "Boot time was around {}:{}:{}".format(boot.hour, boot.minute, boot.second)
print(bootime)
Upvotes: 3