- WMI Fun !! -|WMI StepWMI SampleSearchWMI Fun !! GroupsAbout WMI Fun !!
Top Page >> WMI Step >> イベントログ(セキュリティ)の内容を取得する
イベントログ(セキュリティ)の内容を取得する
Topics

セキュリティのイベントログの内容を取得するサンプルです。Win32_NTLogEventクラスを使用します。


Sample Code

Private Sub Command1_Click()

Dim EveSet As SWbemObjectSet
Dim Eve As SWbemObject
Dim Locator As SWbemLocator
Dim Service As SWbemServices
Dim Security As SWbemSecurity
Dim MesStr As String

Set Locator = New WbemScripting.SWbemLocator
Set Security = Locator.Security_
Security.Privileges.Add wbemPrivilegeSecurity, True
Set Service = Locator.ConnectServer

Set EveSet = Service.ExecQuery _
    ("Select * From Win32_NTLogEvent Where Logfile='Security' " & _
    "And TimeGenerated > '2005/07/01'")

For Each Eve In EveSet

    MesStr = MesStr & Eve.EventCode & ":" & Eve.Message
  
Next

MsgBox "イベントログ(セキュリティ)の内容です。" & vbCrLf & _
            vbCrLf & MesStr

Set EveSet = Nothing
Set Eve = Nothing
Set Locator = Nothing
Set Service = Nothing
Set Security = Nothing

End Sub

Comment

実行すると2005年7月1日以降に発生したセキュリティのイベントログを全て表示します。以前公開したイベントログの内容を取得するサンプルと違いセキュリティのログに対してはwbemPrivilegeSecurityという権限を明示的に指定する必要があります。


WMI を本で勉強したい方へ。 Windows PowerShellインアクション を読んでみては?
なかなか WMI のことが乗っている書籍は少ないですが…管理系業務に係る方には楽しめるかも?
パソコンで目が疲れたら、ブルーベリーアイ
『ブルーベリーアイ』1粒中ビルベリーエキス160mg【楽天シニア市場】
 ^ Copyright(C) 1997-2008 とお All rights reserved. <<