トップ回答者
バックアップしたイベントログをVB.NETで開きたい

質問
-
OS:Windows2012R2
開発言語:VB.NET2012
バックアップしたイベントログ( C:\Windows\System32\winevt\Logs\Archive-Security-2015-01-21-08-00-07-577.evtx)をVB.NETで取り込み、ログの詳細を検索したいのですが、どのようにしたら良いかわかりません。
通常のイベントログの取り込み、ログ詳細検索はできています。
ご存知の方がいらっしゃいましたら、ご教示願います。
'取得するイベントログ名
Dim logName As String = "Security"
'コンピュータ名("."はローカルコンピュータ)
Dim machineName As String = "."
'System.Diagnostics.EventLog.SourceExists()
'指定したイベントログが存在しているか調べる
If System.Diagnostics.EventLog.Exists(logName, machineName) Then
ListBox1.Items.Clear()
'EventLogオブジェクトを作成する
Dim log As New System.Diagnostics.EventLog(logName, machineName)'ログエントリをすべて取得する
For Each entry As System.Diagnostics.EventLogEntry In log.Entries'ログエントリのメッセージを出力する
If entry.InstanceId = "4624" Then
If entry.ReplacementStrings(8) = "10" Then
ListBox1.Items.Add(entry.TimeWritten.ToString("yyyy/MM/dd HH:mm:ss") & _
" " & entry.ReplacementStrings(8) & _
" " & entry.ReplacementStrings(5) & _
" " & entry.ReplacementStrings(18))End If
End If'ログエントリのメッセージを出力する
If entry.InstanceId = "4625" Then
ListBox1.Items.Add(entry.TimeWritten.ToString("yyyy/MM/dd HH:mm:ss") & _
" " & entry.ReplacementStrings(8) & _
";" & entry.ReplacementStrings(13) & _
" " & entry.ReplacementStrings(5) & _
" " & entry.ReplacementStrings(19))
End IfNext
'閉じる
log.Close()
Else
MsgBox("イベントログが見つかりません")
End If
MsgBox("OK")- 編集済み 柏崎 2015年1月29日 7:08
回答
すべての返信
-
trapemiyaさん
回答ありがとうございます。
サンプルを使って試しているのですが、Securityログの詳細情報にアクセスできなようです。
もしご存知の様でしたらアドバイスをお願いします。
Public Sub QueryExternalFile()
Dim queryString As String = "*[System/Level=4]" ' XPATH Query
' Dim eventLogLocation As String = "C:\MyEvents.evtx"
Dim eventLogLocation As String = "C:\Windows\System32\winevt\Logs\Archive-Security-2015-01-21-08-00-07-577.evtx"Dim eventsQuery As New EventLogQuery(eventLogLocation, PathType.FilePath, queryString)
Try
Dim logReader As New EventLogReader(eventsQuery)Dim eventInstance As EventRecord = logReader.ReadEvent()
While Not eventInstance Is Nothing
' Display event info
Console.WriteLine("-----------------------------------------------------")
Console.WriteLine("Event ID: {0}", eventInstance.Id)
Console.WriteLine("Publisher: {0}", eventInstance.ProviderName)
Console.WriteLine("Description: {0}", eventInstance.FormatDescription())
eventInstance = logReader.ReadEvent()
End WhileCatch e As EventLogNotFoundException
Console.WriteLine("Could not find the external log to query! " & e.Message)
Return
End Try
End Sub