| - WMI Fun !! -|WMI Step|WMI Sample|Search|WMI Fun !! Groups|About WMI Fun !! | ||||||
| Top Page >> WMI Step >> イベントログの内容を保存する | ||||||
|
イベントログの内容を保存する
■Topicsイベントログの内容を保存するサンプルです。Win32_NTLogEventFileクラスを使用します。 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 Ret As Long
Const wbemPrivilegeBackup = 16
Set Locator = New WbemScripting.SWbemLocator
Set Security = Locator.Security_
Security.Privileges.Add wbemPrivilegeBackup
Set Service = Locator.ConnectServer
Set EveSet = Service.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Application'")
For Each Eve In EveSet
Ret = Eve.BackupEventLog("c:\applicationlog.evt")
Next
If Ret = 0 Then
MsgBox "アプリケーションログの保存に成功しました。"
Else
MsgBox "アプリケーションログの保存に失敗しました。"
End If
Set EveSet = Nothing
Set Eve = Nothing
Set Locator = Nothing
Set Service = Nothing
Set Security = Nothing
End Sub
実行するとイベントログの中のアプリケーションログをcドライブに保存します。もちろんアプリケーションログ以外にもソースを変更すれば保存可能です。LogFileNameプロパティをシステムログであれば「System」、セキュリティログであれば「Security」を指定します。 以前PCをシャットダウンサンプルで紹介したとおり今回の保存行為にも特権が必要です。wbemPrivilegeBackupをバックアップを行う特権があることを明示的に指定し、WMIへ接続を行っています。
WMI を本で勉強したい方へ。
なかなか WMI のことが乗っている書籍は少ないですが…管理系業務に係る方には楽しめるかも? |
|
| ^ | Copyright(C) 1997-2008 とお All rights reserved. | << |