Page 1 of 1 1
Topic Options
#197504 - 2010-01-22 11:09 PM event log
Hari_Kata Offline
Fresh Scripter

Registered: 2008-01-20
Posts: 5
Loc: KL
Hi

$_objWMIQuery="SELECT * FROM Win32_NTLogEvent WHERE Logfile='System' and EventCode=10005"
$_colItems = $_objWMIService.ExecQuery($_objWMIQuery,,48)
If @ERROR $_colItems = 0 Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
For Each $_objItem In $_colItems
?$_objItem.Message
Next
$_colItems = 0

Above mentioned code is displaying the following output.

"COM got error "%1058" attempting to start the service wuauserv with arguments "
in order to run the server:
{E60687F7-01A1-40AA-86AC-DB1CBF673334}

where as the actual Message in the system event log is as follows.

DCOM got error "The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. " attempting to start the service wuauserv with arguments "" in order to run the server:
{E60687F7-01A1-40AA-86AC-DB1CBF673334}

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

How can i display the whole message correctly?

Top
#197505 - 2010-01-22 11:52 PM Re: event log [Re: Hari_Kata]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Hari,

I initially thought you did not include the GetObject, and you did not, but now understand what is going on..
 Code:
BREAK ON
CLS
$_strComputer = "."
$_objWMIService = GetObject("winmgmts:\\" + $_strComputer + "\root\CIMV2")
$_objWMIQuery="SELECT * FROM Win32_NTLogEvent WHERE Logfile='System' and EventCode=10005"
$_colItems = $_objWMIService.ExecQuery($_objWMIQuery,,48)
If @ERROR $_colItems = 0 Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf 
For Each $_objItem In $_colItems 
?$_objItem.Message
Next
$_colItems = 0

?'Press a key..'
get $


Yep.. Running this through the "Scripting Guys: Script-O-Matic" we get the same thing..

 Quote:

Category: 0
CategoryString:
ComputerName: COMPUTER-DYER
Data:
EventCode: 10005
EventIdentifier: -1073731819
EventType: 1
InsertionStrings: 1053,WSearch,,{7D096C5F-AC08-4F1F-BEB7-5C22C517CE39}
Logfile: System
Message: DCOM got error "%1053" attempting to start the service WSearch with arg
uments ""
in order to run the server:
{7D096C5F-AC08-4F1F-BEB7-5C22C517CE39}

RecordNumber: 1966
SourceName: DCOM

TimeGenerated: 8/14/2009 11:01:09 AM

TimeWritten: 8/14/2009 11:01:09 AM
Type: error
User: NT AUTHORITY\SYSTEM


Oh, and BTW, you may want to look for WMIQuery over in the UDF Section as well..

Also, here is a script I put together that I use to e-mail yesterday's Event Log errors every day. It is in VBScript -
 Code:
Option Explicit
Dim wbemFlagReturnImmediately, wbemFlagForwardOnly, IFlags
Dim strComputer, yMonth, yDay, cyYear, yyYear, DateToCheck
Dim objWMIService, dtmStartDate, dtmEndDate, DataList, colLoggedEvents
Dim AttDoc, FileSystem, oFile, objEvent, Message

 Const CONVERT_TO_LOCAL_TIME = True
 Const adVarChar = 200
 'Const MaxCharacters = 900
 
 wbemFlagReturnImmediately = 16
 wbemFlagForwardOnly = 32
 IFlags = wbemFlagReturnImmediately + wbemFlagForwardOnly
 
 On Error Resume Next
 strComputer = "."
 
 'Connect To WMI
 Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate,(Security)}!\\" & _
 strComputer & "\root\cimv2")

 yMonth = Right(100 + Month(Date() - 1), 2)
 yDay = Right(100 + Day(Date() - 1), 2)
 cyYear = Left(Year(Date() - 1), 2)
 yyYear = Right(100 + Year(Date() - 1), 2)
 
 DateToCheck = Date()

 dt_name = Left(Starttm,2) & Mid(Starttm,4,2) & Mid(Starttm,7,4)
 
 'Get yesterday In UTC
 Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
 dtmStartDate.SetVarDate DateToCheck - 1, CONVERT_TO_LOCAL_TIME
 'Get Today In UTC
 Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
 dtmEndDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME

 ' Create disconnected dataset To sort found events by Time
 ' the WMI scan collects events from newest To oldest
 Set DataList = CreateObject("ADOR.Recordset")
 DataList.Fields.Append "TimeGenerated", adVarChar, 50
 DataList.Fields.Append "EventCode", adVarChar, 10
 DataList.Fields.Append "Logfile", adVarChar, 50
 DataList.Fields.Append "Type", adVarChar, 50
 DataList.Fields.Append "Message", adVarChar, 8192
 DataList.Open

 Set colLoggedEvents = objWMIService.ExecQuery _
 ( "Select * From Win32_NTLogEvent Where Logfile = 'Application' " & _
 "And TimeWritten >= '" & _
 dtmStartDate & _
 "' And TimeWritten < '" & _
 dtmEndDate & _
 "'",, IFlags )

 'EventType Value = Meaning
 ' 1 = Error
 ' 2 = Warning
 ' 3 = Information
 ' 4 = Security Success
 ' 5 = Security Failure
 ' 8 = Security audit success
 ' 16 = Security audit failure

 'CCYYMMDD.csv

 AttDoc = cyYear & yyYear & yMonth & yDay & ".csv"

 Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
 Set oFile = FileSystem.CreateTextFile(AttDoc, True)

 ' Event properties are:
 ' objEvent
 ' Category
 ' CategoryString
 ' ComputerName
 ' Data
 ' EventCode
 ' EventIdentifier
 ' EventType
 ' InsertionStrings
 ' Logfile
 ' Message = DESCRIPTION
 ' RecordNumber
 ' SourceName
 ' TimeGenerated
 ' TimeWritten
 ' Type
 ' User

 ' -- Write a header to the logfile
 oFile.WriteLine("TimeGenerated,EventCode,LogFile,Type,Message")

 ' -- Build the RecordSet
 For Each objEvent In colLoggedEvents
     'Wscript.Echo objEvent.TimeGenerated
     DataList.AddNew
     DataList("TimeGenerated") = objEvent.TimeGenerated
     DataList("EventCode") = objEvent.EventCode
     DataList("Logfile") = objEvent.Logfile
     DataList("Type") = objEvent.Type
     DataList("Message") = objEvent.Message
     Message = Replace(DataList("Message"), vbcrlf, " ")
     Message = Replace(Message, Chr(34), Chr(34) & Chr(34))
     Message = Trim(Message)
     If InStr(Message, Chr(10)) Then
         Message = Chr(34) & Message & Chr(34)
     Else
         Message = Message
     End If
     DataList("Message") = Message
     DataList.Update
 Next

 DataList.Sort = "TimeGenerated"
 'DataList.Sort = "strRecordNumber"
 DataList.MoveFirst 'oldest to newest
 Do Until DataList.EOF
 'DataList.MoveLast 'newest to oldest
 'Do Until DataList.BOF
     oFile.WriteLine(evtdatetime(DataList.Fields.Item("TimeGenerated")) & "," & _
     DataList.Fields.Item("EventCode") & _
     "," & _
     DataList.Fields.Item("Logfile") & _
     "," & _
     DataList.Fields.Item("Type") & _
     "," & _
     DataList.Fields.Item("Message"))
     DataList.MoveNext
     ' - original - Loop
     'DataList.MovePrevious
 Loop

 WScript.Echo "Done!!"
     
 WScript.quit

 Function evtdatetime(evttime)
     Dim tmGen, dtPart, tmPart
     tmGen = Left(evttime, 14)
     dtPart = Left(tmGen, 8)
     tmPart = Right(tmGen, 6)
     evtdatetime = Mid(dtPart, 5, 2) & "/" & Right(dtPart, 2) & "/" & Left(dtPart, 4) & " " & _
    Left(tmPart, 2) & ":" & Mid(tmPart, 3, 2) & ":" & Right(tmPart, 2)
End Function



HTH,

Kent


Edited by Kdyer (2010-01-23 12:24 AM)
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#197506 - 2010-01-23 01:05 AM Re: event log [Re: Kdyer]
Hari_Kata Offline
Fresh Scripter

Registered: 2008-01-20
Posts: 5
Loc: KL
Kdyer,

Checked the code with WMIQuery UDF. But no go. Same output as my code.

From previous posts, Glenn played with event logs.

Glenn,

Any help from your side in this issue ...............

Top
#197507 - 2010-01-23 01:22 AM Re: event log [Re: Hari_Kata]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Hari,

Two things..

Doing a Google search on: wuauserv

We see the following - Repair or reinstall Windows Automatic Update service (wuauserv) not WSUS
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_22522876.html


Accessing Automatic Updates Configuration.
http://www.amset.info/windows/auto-updates.asp

The other thing is that you never instantiate the object for WMI in the original script - unless you are not showing all of the code.

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#197508 - 2010-01-23 02:57 AM Re: event log [Re: Hari_Kata]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
I don't have anything to extract data from the event logs themselves. I have an app that dumps the event logs nightly, and then extract the data from that.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197510 - 2010-01-23 02:51 PM Re: event log [Re: Glenn Barnas]
Hari_Kata Offline
Fresh Scripter

Registered: 2008-01-20
Posts: 5
Loc: KL
Kdyer,

I ran your vb script for my event. It also giving the wrong output as my code.

Found that when the script is unable to get the string which is in between ". It is just omitting the part in between or giving some other.

Now my question is, how can i check if " is present in a string?

Top
#197515 - 2010-01-24 01:33 AM Re: event log [Re: Hari_Kata]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
 Originally Posted By: Hari_Kata

Found that when the script is unable to get the string which is in between ". It is just omitting the part in between or giving some other.


Hari,

Have another look at the code that I provided..

 Code:
     If InStr(Message, Chr(10)) Then
         Message = Chr(34) & Message & Chr(34)
     Else
         Message = Message
     End If
     DataList("Message") = Message
     DataList.Update


It should be something like..
 Code:
     If InStr(Message, Chr(34)) Then
         Message = REPLACE(Message,""","")
     Else
         Message = Message
     End If
     DataList("Message") = Message
     DataList.Update



HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#197522 - 2010-01-25 03:44 AM Re: event log [Re: Kdyer]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
There's already a ReadEventlog UDF posted in the UDF Forum.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 601 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.192 seconds in which 0.155 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org