Re: WMI LastBootUpTime wrong value
From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 04/22/04
- Next message: Mike Brearley: "batch into script"
- Previous message: Richard Mueller [MVP]: "Re: WSH - How execute security patch on remote NT4 Workstation.."
- In reply to: Text: "WMI LastBootUpTime wrong value"
- Messages sorted by: [ date ] [ thread ]
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 > > > > > > > > >
- Next message: Mike Brearley: "batch into script"
- Previous message: Richard Mueller [MVP]: "Re: WSH - How execute security patch on remote NT4 Workstation.."
- In reply to: Text: "WMI LastBootUpTime wrong value"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|