The Event Viewer is a program that's included with Microsoft operating systems. The Event Viewer lets administrators and users monitor events through event logs. Events are generated when an error is detected such as if a user authentication fails. Visual Basic.NET (VB.NET) is a computer object-oriented programming language developed by Microsoft. VB.NET is commonly used due to its flexibility and ease of use. In a few steps you can write VB.NET code to read the Event Viewer in your system.
- Skill level:
- Moderately Easy
Other People Are Reading
Start Microsoft Visual Basic Express and click "New Project..." on the left pane of your screen. Double-click "Windows Forms Application" to start your new project.
Double-click "Button" on the "Tools" pane to create a new button. Double-click "ListBox" on the "Tools" pane to create a new list box control. Double-click "Button1" to open the "Form1.vb" module.
Press "Ctrl+A" and press "Delete" to delete all code.
Copy and paste the following code to your "Form1.vb" module.
Public Class Form 1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim eventLogApp As New System.Diagnostics.EventLog("Application") Dim eventLogEntry As System.Diagnostics.EventLogEntry Dim eventCntr As Integer = 1 For Each eventLogEntry In eventLogApp.Entries Me.ListBox1.Items.Add("Event Number:" & eventCntr) Me.ListBox1.Items.Add(eventLogEntry.EntryType.ToString) Me.ListBox1.Items.Add(eventLogEntry.TimeGenerated.ToString) Me.ListBox1.Items.Add(eventLogEntry.Source.ToString) Me.ListBox1.Items.Add(eventLogEntry.Category.ToString) Me.ListBox1.Items.Add(eventLogEntry.EventID.ToString) Me.ListBox1.Items.Add(eventLogEntry.MachineName.ToString) Me.ListBox1.Items.Add(eventLogEntry.Message.ToString) Me.ListBox1.Items.Add("-----------------------------------------------") eventCntr = eventCntr + 1 Me.ListBox1.Refresh() Next End Sub
Start your program by pressing "F5" and then clicking "Button1" to display event log entries through a list box.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for