Re: WMI Date works on XP but not 2000 Server

From: nbullock (niel_bullock_at_hotmail.com)
Date: 04/21/05


Date: Thu, 21 Apr 2005 10:08:24 -0500

Thank you for the code... I am also trying to export the actual users name
to this database. However, it appears that is listed in an
"InsertionsStrings", which I belive is an Array. Is is possible to loop for
values in that array and insert all values in the same table list in the
code below? I am not sure it the Name is always in the same array address.

On Error Resume Next

Set objOU = GetObject("LDAP://OU=Domain Controllers,dc=sblhs,dc=net")
objOU.Filter = Array("Computer")

For Each objComputer in objOU
    strComputer = objComputer.CN

Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=EventLogs;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM EventTable" , objConn, 3, 3

Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRetrievedEvents = objWMIService.ExecQuery _
 ("Select * from Win32_NTLogEvent Where EventCode ='529'")

Set colEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
        & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")

For Each objEvent in colEvents
    objRS.AddNew
    objRS("Category") = objEvent.Category
    objRS("ComputerName") = objEvent.ComputerName
    objRS("EventCode") = objEvent.EventCode
    objRS("Message") = objEvent.Message
    objRS("RecordNumber") = objEvent.RecordNumber
    objRS("SourceName") = objEvent.SourceName
    objRS("TimeWritten") = objEvent.TimeWritten
    objRS("Type") = objEvent.Type
    objRS("User") = objEvent.User
'This needs to be called for the user name
' For Each propValue In objItem.InsertionStrings
 ' WScript.Echo "InsertionStrings: " & propValue

    objRS.Update
Next

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:42677430.50603@hydro.com...
> 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



Relevant Pages

  • Re: Win32_ScheduledJob in Windows 2000 Pro
    ... here's the relevant code: ... You will need to build the time format yourself, see example below, ... If TZOffset < 0 Then ... 'Read time zone offset hex value from Registry. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: WMI Date works on XP but not 2000 Server
    ... You will need to build the time format yourself, see example below, ... If TZOffset < 0 Then ... Function TimeZoneOffset ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.security)
  • Re: Change the Time Zone on Windows 2003
    ... Time zone change using the command line utility Control.exe ... Input value behind /Z is from the Display value under the registry key ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.scripting.wsh)
  • Re: RUNAS!?!?!?....SU!?!?!?
    ... I believe the preferred method to change time zone on a computer is to use ... I remember reading somewhere that changine settings in the ... > Microsoft MVP Scripting and ADSI ... >> Windows Registry Editor Version 5.00 ...
    (microsoft.public.windows.server.scripting)
  • Re: Change the Time Zone on Windows 2003
    ... > Time zone change using the command line utility Control.exe ... > Input value behind /Z is from the Display value under the registry key ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.wsh)

Quantcast