Re: WMI LastBootUpTime wrong value

From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 04/22/04


Date: Thu, 22 Apr 2004 11:59:42 -0500

Hi,

The time is stored in UTC. To convert to local time you need to adjust using
the time zone bias stored in the local registry. Your time zone is 5 hours
from UTC, but with daylight savings the correction is now 4 hours. I adjust
using the following registry setting:

HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias

The "Bias" value is the number of minutes your time zone is west of the
prime meridian. The "ActiveTimeBias" is the number of minutes, but taking
daylight savings into account. I generally convert time values to the local
time on my computer, rather than the local time appropriate for the remote
machines (which might be in other time zones). That's so all values can be
compared. You might decide otherwise.

I use code similar to below to determine the correction in minutes:

' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
  & "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
  lngBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
  lngBias = 0
  For k = 0 To UBound(lngBiasKey)
    lngBias = lngBias + (lngBiasKey(k) * 256^k)
  Next
End If

The value is "Long" on clients with NT or above, but "Variant()" on Win9x.

-- 
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
"Text" <mas@mas.com> wrote in message news:4087e442$1_2@127.0.0.1...
> I am working on an uptime script for servers and can't seem to get an
> accurate time when I query  objItem.LastBootUpTime from
> Win32_OperatingSystem. It always 4:00 hours too early.
> If the server logs and uptime.exe say the server is upt 4 hours. My wmi
> reports the server came up 4 hours before that. I am on eastern time. I
> guess its my off set from UTC time, but I can't figure out how to deal
with
> that
>
>
> Dim objWMIService
> Dim colItems
> Dim endfile
>
> Set fs = CreateObject("Scripting.FileSystemObject")
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("Select * from
> Win32_OperatingSystem",,48)
> For Each objItem in colItems
>  WScript.Echo "LastBootUpTime: " & objItem.LastBootUpTime
>  WScript.Echo "LocalDateTime: " & objItem.LocalDateTime
>  strvalue1 = dtparse(objItem.LastBootUpTime)
>   strvalue2 = dtparse(objItem.LocalDateTime)
>  WScript.Echo strvalue1 & " " & strvalue2 & "  strvalues"
>  intday = DateDiff("d", strvalue1, strvalue2)
>  inthour = DateDiff("h", strvalue1, strvalue2)
>  intmin = DateDiff("n", strvalue1, strvalue2)
>  WScript.Echo (inthour \ 24)  & " day(s) " & (inthour Mod 24) & " hours "
&
> (intmin Mod 60) & " minutes"
>  Next
>
>
> Function dtparse(strvalue) 'this function parses the Time into a readable
> format.
> stryear = Left(strvalue, 4)
> strmonth= Mid(strvalue, 5,2)
> strday = Mid (strvalue, 7,2)
> strhour = Mid(strvalue, 9,2)
> strmin = Mid(strvalue, 11,2)
> strsec = Mid(strvalue, 13,2)
> strmsec = Mid(strvalue, 16,6)
> strtz = Right(strvalue, 4)
>
>
> strdate = strmonth & " " & strday & ", " & Stryear
> strtime = strhour & ":" & strmin & ":" & Strsec
>
> dtparse = CDate(strdate & " " & strtime)
> End Function
>
>
>
>
>
>
>
>
>


Relevant Pages

  • Re: garbage computer accounts
    ... > One needs to use the Time Zone bias allowing for the state of Summer ... > Time at the time; Windows can only AIUI give what the local time ... this conversion assumes that daylight savings never changes. ...
    (microsoft.public.scripting.wsh)
  • Re: OpenMPE redux, executive view.
    ... and have everyone see everything in their local time. ... [time zone variable set for time zone where the system is located] ... Current value of Time Zonevariable: PST8PDT ... Notice the CTIME function returns the Pacific time according to the ...
    (comp.sys.hp.mpe)
  • Re: What time is it? Issues with Local time, system time, DST
    ... be for local time, not UTC. ... RTC, so that when processor is asleep or off, onboard batteries ... So is the standard way to handle this to store time zone and DST state ... The time zone which is set for the device is stored in the registry by ...
    (microsoft.public.windowsce.platbuilder)
  • Re: What time is it? Issues with Local time, system time, DST
    ... works with a server that could be in a different time zone, ... is expecting to be local time. ... not the coordination of two (RTC, ... implemented years ago and we had trouble getting registry persistence ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Time and Date Synchronization - 1 hour difference
    ... There's nothing that you can do if you must continue using the old registry. ... You'd have to patch, somehow, the time zone settings in this old registry ... added a new function that is when press "OK"button in Date/Time Properties ... I checked the checkbox on *both* devices,and the sync time still have ...
    (microsoft.public.windowsce.platbuilder)