| - WMI Fun !! -|WMI Step|WMI Sample|WMI Reference|WMI LibraryLinks|About WMI Fun !! |
|
|
|
|
Home > WMI Sample > イベントログの内容を保存する
|
|
イベントログの内容を保存する: Win32_NTEventLogFile
■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ドライブにapplicationlog.evtという名前で保存します。もちろんアプリケーションログ以外にもソース上のWQLにてクエリー条件を変更すれば保存可能です。LogFileNameプロパティをシステムログであれば「System」、セキュリティログであれば「Security」を指定します。 なおWMIの使い方(VB6,VBS,VB.NET,VC#,PowerShell対象)に関してはWMI Stepも参考にしてみてください。
|
|
ご意見・ご感想をこちらのアンケートからお待ちしています
解らないIT/パソコン用語は - WMI Fun !! - http://www.wmifun.net/ Microsoft社のテクノロジーであるWMI(Windows Management Instrumentation)の使い方を Visual Basicを使ってのんびり公開しています VBや.Net Framework(VB,C#)以外でもWSH(VBS)やPowerShellなどのスクリプトでも使えますよ! 資産管理や監視業務の効率化、システム系ツール開発にお勧めです This web site created by Toh. Copyright(C) 1997-2010 WMI Fun !!. All rights reserved. このサイトへのリンクはフリーです |
| ∧ ページの先頭へ… |