I hope that could help others.
to use the function
Code:
' GetUpTime Local lBootTime As String Local lCurrentTime As String Local lUpTime As String If GetUpTime(lBootTime, lCurrentTime, lUpTime) = %TRUE Then ' do what you want with these 3 variables ' see example in the picture End If
Code:
Type SYSTEM_TIMEOFDAY_INFORMATION BootTime As Filetime CurrentTime As Filetime End Type Declare Function NtQuerySystemInformation Lib "NtDLL.DLL" Alias "NtQuerySystemInformation"( _ ByVal SystemInformationClass As Dword, _ ByVal SystemInformation As Dword, _ ByVal SystemInformationLength As Dword, _ ByRef ReturnLength As Dword) As Long %SystemTimeInformation=3 Function GetUpTime(ByRef pBootTime As String, ByRef pCurrentTime As String, ByRef pUpTime As String) As Long Local lGetUpTime As Long : lGetUpTime = %FALSE Local lSystemTimeInformation As SYSTEM_TIMEOFDAY_INFORMATION ' UpTime Local lSign, lDays, lHours, lMinutes, lSeconds As Long ' SystemTime Local lSTBootTime As SystemTime Local lSTCurrentTime As SystemTime ' IPowerTime Local IPTBootTime As IPowerTime : Let IPTBootTime = Class "PowerTime" Local IPTCurrentTime As IPowerTime : Let IPTCurrentTime = Class "PowerTime" ' Use NtQuerySystemInformation to retrieve BootTime and CurrentTime information If NtQuerySystemInformation(%SystemTimeInformation, VarPtr(lSystemTimeInformation), SizeOf(lSystemTimeInformation), %Null) = %STATUS_SUCCESS Then lGetUpTime = %TRUE ' FileTimeToLocalFileTime FileTimeToLocalFileTime(lSystemTimeInformation.BootTime ,lSystemTimeInformation.BootTime) FileTimeToLocalFileTime(lSystemTimeInformation.CurrentTime,lSystemTimeInformation.CurrentTime) ' FileTime to SystemTime conversion FileTimeToSystemTime(lSystemTimeInformation.BootTime , lSTBootTime) FileTimeToSystemTime(lSystemTimeInformation.CurrentTime, lSTCurrentTime) ' IPowerTime BootTime IPTBootTime.NewDate(lSTBootTime.wYear,lSTBootTime.wMonth , lSTBootTime.wDay) IPTBootTime.NewTime(lSTBootTime.wHour,lSTBootTime.wMinute, lSTBootTime.wSecond) pBootTime = IPTBootTime.DateString+" "+IPTBootTime.TimeStringFull) ' IPowerTime CurrentTime IPTCurrentTime.NewDate(lSTCurrentTime.wYear,lSTCurrentTime.wMonth , lSTCurrentTime.wDay) IPTCurrentTime.NewTime(lSTCurrentTime.wHour,lSTCurrentTime.wMinute, lSTCurrentTime.wSecond) pCurrentTime = IPTCurrentTime.DateString+" "+IPTCurrentTime.TimeStringFull) ' UpTime = timediff CurrentTime - BootTime IPTCurrentTime.timediff IPTBootTime, lSign, lDays, lHours, lMinutes, lSeconds pUpTime = Format$(lDays)+"d "+Format$(lHours)+"h "+Format$(lMinutes)+"m "+Format$(lSeconds)+"s" End If Function = lGetUpTime End Function