Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about event viewer id log

Status
Not open for further replies.

brlissab

Technical User
Oct 11, 2002
35
CH
hello
i'm working on logs on wk3 server and i am searching for a way to search some id events on event vwer and those selected will be write on a text file..
here is my code
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFso.createTextFile("C:\scripts\LogID.txt")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")

For Each objEvent in colLoggedEvents
            if ErrorEvent(objEvent) Then
        objFile.WriteLine   ("Event Code: ") & objEvent.EventCode & vbCrlf & _
        objFile.WriteLine  ("Event Type: ") & objEvent.Type & vbCrlf & _
        objFile.WriteLine ("Message: ") & objEvent.Message
End If
Next

Function ErrorEvent(eventid)
 objectEvent=False
If objEvent.Type(param)="Error" Then
Set objEvent=True
End If
End Function

yeah it is not very developped, actually im also looking to
repair these errors, browsing technet for eventually a list of these event id on my wk3 server...if someone nows something about it glad to know..
feel free to comment my code
thanks
 
Drop the ErrorEvent(eventid) function. It is so wrong. In the main, replace the line
>[tt]if ErrorEvent(objEvent) Then[/tt]
by this
[tt]if objEvent.eventtype=1 then[/tt]
 
Also ending the writeline with "& _" is wrong syntactically. And vbcrlf preceding it is not needed until you want to separate line by a blank line.
>[tt] objFile.WriteLine ("Event Code: ") & objEvent.EventCode [red]& vbCrlf & _[/red][/tt]
[tt] objFile.WriteLine "Event Code: " & objEvent.EventCode [/tt]
etc...
 
i give a try on, but nothing...
Code:
set objFso = createObject("Scripting.FileSystemObject")
set objFile = objFso.CreateTextFile("d:scripts\logID.txt")

strComputer = "."
set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        
        Set colLoggedEvents = objWMIService.ExecQuery _
        ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")
        
        For Each objEvent in colLoggedEvents
        if objEvent.eventype=1 Then
        objFile.WriteLine   "Event Code: " & objEvent.EventCode
        objFile.WriteLine   "Event type: " & objEvent.Type
End IF
Next
and sorry for my first code, i've been scripting vbs a bit, but wmi(heard about it before...)only since couple days..
need to have some info to work on it first i think..
 
My line
[tt] if objEvent.eventtype=1 then[/tt]
Your line
[tt] if objEvent.eventype=1 Then[/tt]
What is the material difference?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top