事件日志-获取最后一个访问文件的用户 [英] Event Log - Get last user to access a file

查看:52
本文介绍了事件日志-获取最后一个访问文件的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

谁能指出一些示例代码来读取系统事件日志,以确定最后一个写入/保存文件的用户/应用.当然在VB中. :)

Can anyone point me to some sample code to read the system event log to determine the last user/app to write/save a file.  In VB of course. :)

我一直指责googlin,找不到我可以吞噬的例子. :):)

I have been googlin my fingers of and I can't find an example I can cannibalize.  :) :)

谢谢

-NJ

推荐答案

NJDevils28,

Hi NJDevils28,

我阅读了下面代码中的最新10条记录,并在列表框中排名,请参阅.

I read the latest 10 records in the code below, and rank in the listbox, please refer to.

Public Class ReadForm
    ' Stores the name of the log that the user wants to view.
    Private logType As String = ""

    Private Sub cmdViewLogEntries_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewLogEntries.Click
        Try
            Const EntriesToDisplay As Integer = 10

            ' In this case the EventLog constructor is passed a string variable for the log name.
            ' This is because the user of the application can choose which log they wish to view 
            ' from the listbox on the form.
            Dim ev As New EventLog(logType, System.Environment.MachineName, _
                "Event Log Sample")

            rchEventLogOutput.Text = "Event log entries (maximum of 10), newest to oldest." & vbCrLf & vbCrLf

            Dim lastLogToShow As Integer = ev.Entries.Count - EntriesToDisplay
            If lastLogToShow < 0 Then
                lastLogToShow = 0
            End If

            ' Display the last 10 records in the chosen log.
            For index As Integer = ev.Entries.Count - 1 To lastLogToShow Step -1
                Dim CurrentEntry As EventLogEntry = ev.Entries(index)
                rchEventLogOutput.Text &= "Event ID : " & CurrentEntry.InstanceId & vbCrLf
                rchEventLogOutput.Text &= "Entry Type : " & _
                    CurrentEntry.EntryType.ToString() & vbCrLf
                rchEventLogOutput.Text &= "Message : " & _
                    CurrentEntry.Message & vbCrLf & vbCrLf
            Next
        Catch secEx As System.Security.SecurityException
            MsgBox("Security exception in reading the event log.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        Catch ex As Exception
            MsgBox("Error accessing logs on the local machine.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        End Try
    End Sub

    Private Sub lstEntryType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntryType.SelectedIndexChanged
        ' Store the log that the user selected in the ListBox
        logType = CType(lstEntryType.Items(lstEntryType.SelectedIndex()), String)
    End Sub

    Private Sub ReadForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            For Each currentLog As EventLog In EventLog.GetEventLogs()
                lstEntryType.Items.Add(currentLog.LogDisplayName)
            Next
            lstEntryType.SelectedIndex = 0
        Catch secEx As System.Security.SecurityException
            MsgBox("Security exception in reading the event log.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        Catch ex As Exception
            MsgBox("Error accessing logs on the local machine.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        End Try
    End Sub

    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

End Class

更多详细信息,请参考 此示例.

More detailed info, please refer to this sample.

最好的问候,

Cherry Bu

Cherry Bu


这篇关于事件日志-获取最后一个访问文件的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆