copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
Beispiel: VB .Net - EventLogs - Namen auflisten
'
Option Explicit On
Option Strict On

Public Class Form1

    Private List As New List(Of String)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        Try
            If List IsNot Nothing Then
                Me.ListBox1.Items.AddRange(List.ToArray())
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private _machinename As String = String.Empty
    Private Property MachineName() As String
        Get
            Return _machinename
        End Get
        Set(ByVal value As String)
            _machinename = value
        End Set
    End Property

    Private Function GetEventLogFriendlyName() As List(Of String)
        If MachineName Is Nothing Then Throw New Exception("Error")
        Try
            Dim Logs() As EventLog = System.Diagnostics.EventLog.GetEventLogs(MachineName)

            For Each Item As EventLog In Logs
                List.Add(Item.LogDisplayName)
            Next
        Catch
            Return Nothing
        End Try
        Return List
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        With Me
            .Text = "EventLogs - Namen auflisten"
            .Button1.Text = "Auflisten"
            .CenterToScreen()
        End With
    End Sub

    Public Sub New()
        InitializeComponent()
        Me._machinename = My.Computer.Name 'oder "."
        Dim t As System.Threading.Thread = New System.Threading.Thread(AddressOf GetEventLogFriendlyName)
        t.Start()
    End Sub

End Class
Sourcecode Visual Basic