473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Query Eventlog by Timewritten field.

1. hism...@dot-solution.net Aug 16, 2:51 pm show options

Newsgroups: microsoft.public.vb.general.discussion
From: hism...@dot-solution.net - Find messages by this author
Date: 16 Aug 2005 11:51:51 -0700
Local: Tues, Aug 16 2005 2:51 pm
Subject: Query Eventlog by Timewritten field.
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse

I am creating a vb.net service that will run AS SERVICE. There is
actually a timer; so the timer will run every 2 minutes and see if
there are any new ERROR type logs in the APPLICATION logs. And if
there are then it will send an email to me ( or whoever I want to
specify). The thing that I can not figure out is how do I create the
query so it queries only thing in the past 2 minutes. If I take the
TimeWritten out of my query it works fine but pulls are the ERROR logs
from APPLICATION logs. This was orginally created in VBSCRIPT but I
have to write it in VB.NET. Here is the code:
Dim dtmStart, SearchEventStart
Dim objWMIService, colEvents, objEvent, EventTime
Dim objMessage, eventCounted, objRecordset, dtDate, dtHour
'
------------------------------*------------------------------*----------

Const eMailAddress = "hashim.ism...@fac.com" ' must be a valid
eMail address!!
Const MinutesToSearchWithin = -2 ' look for the event that
triggered me within the last 2 minutes
objMessage = CreateObject("CDO.Message")
'objMessage.Sender = "NTAdm...@fac.com"
objMessage.To = eMailAddress
dtmStart = CreateObject("WbemScripting.SW*bemDateTime")
SearchEventStart = DateAdd("n", MinutesToSearchWithin, Now())
dtmStart.SetVarDate(SearchEven*tStart, True)
MsgBox(dtmStart, MsgBoxStyle.Information)
objWMIService = GetObject("winmgmts:" _
&
"{impersonationLevel=impersona*te}!\\.\root\cimv2" )
colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile =
'Application' AND type = 'ERROR' AND TimeWritten >= '" & dtmStart &
"'")
' Because we go through all recent events, in case of multiple
events within the last 2 minutes, we might mis
' events. That is: within multiple events that occur within the

last 2 minutes, not for all these events an eMail message
' may be generated. This is a trade-off to avoid generating
multiple eMail messages for one particular event within a
' series of events that occured within the last 2 minutes.
For Each objEvent In colEvents
'On Error Resume Next ' Maybe you should uncomment this
line...
objMessage.TextBody = "Category: " & objEvent.Category
EventTime = Mid(objEvent.TimeWritten, 5, 2) & "/" &
Mid(objEvent.TimeWritten, 7, 2) & "/" & _
Mid(objEvent.TimeWritten, 1, 4) & " " &
Mid(objEvent.TimeWritten, 9, 2) & ":" & _
Mid(objEvent.TimeWritten, 11, 2) & "." &
Mid(objEvent.TimeWritten, 13, 2)
objMessage.From = "NTAd...@fac.com"
objMessage.TextBody = objMessage.TextBody & vbCrLf & "Time:

" & EventTime
objMessage.Subject = "ERROR Event in " &
objEvent.SourceName & " on " & objEvent.ComputerName & " at " &
EventTime
objMessage.TextBody = objMessage.TextBody & vbCrLf &
"EventID: " & objEvent.EventCode
objMessage.TextBody = objMessage.TextBody & vbCrLf &
"Description: " & objEvent.Message
objMessage.TextBody = objMessage.TextBody & vbCrLf &
"RecordNumber: " & objEvent.RecordNumber
objMessage.TextBody = objMessage.TextBody & vbCrLf &
"SourceName: " & objEvent.SourceName
objMessage.TextBody = objMessage.TextBody & vbCrLf & "Type:

" & objEvent.Type
objMessage.TextBody = objMessage.TextBody & vbCrLf & "User:

" & objEvent.User
objMessage.Send()
Next

Nov 21 '05 #1
0 3395

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john s | last post by:
I am trying to create a message text file for the Catagory field in order to map the catagory input number to a string text. I have found some MSDN information on this, but it appears to only be...
2
by: Next | last post by:
Hello all, I have a windows service that was suppose to write some events into its own EventLog. I created the EventLog using the component on VS 2003 toolbar Added an installer for it. Set...
2
by: Tom | last post by:
Is there an object that I can query that will return to me the different logs in the EventLog? I know by default there exist a System, Security and Application Eventl log. But, I'd like to bind...
0
by: jimdscudder | last post by:
I have a second drive on my PC that's a clone of Drive 0. I would like to be view of the system event logs on the other drive: "E:\WINDOWS\system32\config\SysEvent.Evt" This code can't...
0
by: hismail | last post by:
I am creating a vb.net service that will run AS SERVICE. There is actually a timer; so the timer will run every 2 minutes and see if there are any new ERROR type logs in the APPLICATION logs. And...
2
by: HankC | last post by:
This code snippet fails with 'Specified cast is not valid' when running the query to get application warning events in the last 10 days... What am I doing wrong? HankC Dim objWMIService...
3
by: musosdev | last post by:
Hi I'm using the following code in a global class to add to the Windows EventLog every time a try{} catch{} block fails... if(!EventLog.SourceExists("darts"))...
1
by: martin | last post by:
Hi, I'm having some problems with the System.Diagnostics.EventLog class in .NET 2.0 I need to recreate an event message source inside a new log but the messages keeps ending up in the old...
3
by: Ben | last post by:
I am trying to write an eventlog monitor. I am using the sample code provided by VB2005 SDK as the bases for my application. I need to monitor all three logs (application, system, and security)....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.