星期四, 九月 14, 2006

(VB.NET)删除日志文件:(请先备份)

Imports System

Imports System.Management

Module Module1

Public Sub Main()

Dim strComputer = "."

Dim objWMIService, objLogFiles, objLogFile, logs, mylogs( 3)

objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Backup)}!\\" & strComputer & "\root\cimv2")

mylogs(1) = "application"

mylogs(2) = "system"

mylogs(3) = "security"

For Each logs In mylogs

objLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile where LogFileName='" & logs & "'")

For Each objLogFile In objLogFiles

objLogFile.ClearEventLog()

Next

Next

End Sub

End Module

没有评论: