Re: WMI Date works on XP but not 2000 Server
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 04/21/05
- Next message: MVP: "Re: Certificate Server.."
- Previous message: PaulD: "Re: Windows Server 2003 SP1 SCM Permissions"
- In reply to: nbullock: "WMI Date works on XP but not 2000 Server"
- Next in thread: nbullock: "Re: WMI Date works on XP but not 2000 Server"
- Reply: nbullock: "Re: WMI Date works on XP but not 2000 Server"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 21 Apr 2005 11:36:48 +0200
nbullock wrote:
> I am trying to log failed logon attempts to Active Directory. I found this
> example and it works on my XP Pro pc. But it . However:
> ("WbemScripting.SWbemDateTime") will not work on 2000.
>
> We like the idea of logging yesterdays events, and then writing custom
> reports on the data. Does anyone have any suggestions??
> (snip)
Hi
The "WbemScripting.SWbemDateTime" object is not supported on Win2k.
You will need to build the time format yourself, see example below,
will work on all OS versions.
'--------------------8<----------------------
WScript.Echo ConvertToDMTF(Now)
Function ConvertToDMTF(ByVal sTime)
' Return time/date in DMTF format yyyymmddHHMMSS.mmmmmmsUUU
' More on WMI Date and Time Format here:
'http://msdn.microsoft.com/library/en-us/wmisdk/wmi/date_and_time_format.asp
'
' Author: Torgeir Bakken
' Created: 2004-12-04
sDate = Year(sTime) & Right(100 + Month(sTime), 2) _
& Right(100 + Day(sTime), 2)
sTime = Right(100 + Hour(sTime), 2) & Right(100 + Minute(sTime), 2) _
& Right(100 + Second(sTime), 2)
' create time zone part of DMTF
TZOffset = TimeZoneOffset
TZSign = "+" ' init value
If TZOffset < 0 Then
TZOffset = Abs(TZOffset)
TZSign = "-"
End If
' pad TZOffset
TZOffset = Right(1000 + TZOffset, 3)
ConvertToDMTF = sDate & sTime & ".000000" & TZSign & TZOffset
End Function
Function TimeZoneOffset
'Read time zone offset hex value from Registry.
Dim oShell, TZOffset, HexVal
Set oShell = CreateObject("WScript.Shell")
TZOffset = oShell.RegRead("HKLM\SYSTEM\CurrentControlSet\" _
& "Control\TimeZoneInformation\ActiveTimeBias")
'Reg value format varies between Win9x and NT
If IsArray(TZOffset) Then
'Win9x uses a reversed 4 element array of Hex values.
HexVal = Hex(TZOffset(3)) & Hex(TZOffset(2)) _
& Hex(TZOffset(1)) & Hex(TZOffset(0))
Else 'Must be a NT system.
HexVal = Hex(TZOffset)
End If
'Convert to minutes of time zone offset.
TimeZoneOffset = - CLng("&H" & HexVal)
End Function
'--------------------8<----------------------
-- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx
- Next message: MVP: "Re: Certificate Server.."
- Previous message: PaulD: "Re: Windows Server 2003 SP1 SCM Permissions"
- In reply to: nbullock: "WMI Date works on XP but not 2000 Server"
- Next in thread: nbullock: "Re: WMI Date works on XP but not 2000 Server"
- Reply: nbullock: "Re: WMI Date works on XP but not 2000 Server"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|