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, SearchEventStar t
Dim objWMIService, colEvents, objEvent, EventTime
Dim objMessage, eventCounted, objRecordset, dtDate, dtHour
'
------------------------------*------------------------------*----------
Const eMailAddress = "hashim.ism...@ fac.com" ' must be a valid
eMail address!!
Const MinutesToSearch Within = -2 ' look for the event that
triggered me within the last 2 minutes
objMessage = CreateObject("C DO.Message")
'objMessage.Sen der = "NTAdm...@fac.c om"
objMessage.To = eMailAddress
dtmStart = CreateObject("W bemScripting.SW *bemDateTime")
SearchEventStar t = DateAdd("n", MinutesToSearch Within, Now())
dtmStart.SetVar Date(SearchEven *tStart, True)
MsgBox(dtmStart , MsgBoxStyle.Inf ormation)
objWMIService = GetObject("winm gmts:" _
&
"{impersonation Level=impersona *te}!\\.\root\c imv2")
colEvents = objWMIService.E xecQuery _
("Select * from Win32_NTLogEven t 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.Text Body = "Category: " & objEvent.Catego ry
EventTime = Mid(objEvent.Ti meWritten, 5, 2) & "/" &
Mid(objEvent.Ti meWritten, 7, 2) & "/" & _
Mid(objEvent.Ti meWritten, 1, 4) & " " &
Mid(objEvent.Ti meWritten, 9, 2) & ":" & _
Mid(objEvent.Ti meWritten, 11, 2) & "." &
Mid(objEvent.Ti meWritten, 13, 2)
objMessage.From = "NTAd...@fac.co m"
objMessage.Text Body = objMessage.Text Body & vbCrLf & "Time:
" & EventTime
objMessage.Subj ect = "ERROR Event in " &
objEvent.Source Name & " on " & objEvent.Comput erName & " at " &
EventTime
objMessage.Text Body = objMessage.Text Body & vbCrLf &
"EventID: " & objEvent.EventC ode
objMessage.Text Body = objMessage.Text Body & vbCrLf &
"Descriptio n: " & objEvent.Messag e
objMessage.Text Body = objMessage.Text Body & vbCrLf &
"RecordNumb er: " & objEvent.Record Number
objMessage.Text Body = objMessage.Text Body & vbCrLf &
"SourceName : " & objEvent.Source Name
objMessage.Text Body = objMessage.Text Body & vbCrLf & "Type:
" & objEvent.Type
objMessage.Text Body = objMessage.Text Body & vbCrLf & "User:
" & objEvent.User
objMessage.Send ()
Next 0 1192 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 for C/C++.
What I have found in MSDN so far can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/message_files.asp
and...
|
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 all the appropriate properties to assign the new Source to a new log.
For some reason installutil.exe created the source in the correct log. But
|
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 all the different logs dynamically to a dropDownList
control.
Just not sure which object to use.
I looked at Object EventLog but it did not have a method or property to
|
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 do that:
|
by: hismail |
last post by:
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
| |
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 As Object
|
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"))
EventLog.CreateEventSource("darts", "Darts");
EventLog.WriteEntry("darts", msg, EventLogEntryType.Error);
|
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 log?! I have simplified my code into this tiny
snippet:
EventLog.CreateEventSource("mySrc", "myLog1");
|
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). How can I monitor all
three logs at once?
Thanks,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |