Home All Groups Group Topic Archive Search About

Last boot date/time info

Author
14 Oct 2005 12:30 PM
Kjell
Hi

I once saw that boot date and time could be found in the registry
somewhere....

Now, I can't find it again, and I also tryed google for some hints but failed.

pls, say it's possible to get last boot date/time, and maybe a hint how to
do it, or where to look for it....

Yours,  Kjell

Author
14 Oct 2005 2:43 PM
Tom Esh
On Fri, 14 Oct 2005 05:30:03 -0700, "Kjell"
<Kj***@discussions.microsoft.com> wrote:

>
>I once saw that boot date and time could be found in the registry
>somewhere....
>
>Now, I can't find it again, and I also tryed google for some hints but failed.
>
>pls, say it's possible to get last boot date/time, and maybe a hint how to
>do it, or where to look for it....

Not sure where (or if) it's stored in the registry, but here's two
ways to do it with the Api.

1) GetTickCount - returns # of millisecs since last boot. Note this
one wraps every 49 days, plus with VB's signed Long, goes negative
after 24.

'declaration...
Public Declare Function GetTickCount Lib "kernel32" () As Long
'usage...
Dim lBootDate As Date
lBootDate = DateAdd("s", -CDbl(GetTickCount() \ 1000), Now)
Debug.Print lBootDate

2) QueryPerformanceCounter, QueryPerformanceFrequency.

'declares...
Public Declare Function QueryPerformanceCounter Lib "kernel32" _
    (lpPerformanceCount As Currency) As Long
Public Declare Function QueryPerformanceFrequency Lib "kernel32" _
    (lpFrequency As Currency) As Long

'usage...
Dim cFreq As Currency, cCount As Currency
Dim BootDate As Date

If QueryPerformanceFrequency(cFreq) <> 0 Then
    QueryPerformanceCounter cCount
    BootDate = DateAdd("s", -(cCount / cFreq), Now)
    Debug.Print BootDate
End If


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)