K
Kventin
Подскажите, как в получаемом файле добиться, чтобы небыло межстрочных интервалов? Сделал вывод с одну строку через табуляцию-интервалы все равно остались.
Код:
Const strComputer = "."
Dim objFSO, objWMIService, colEvents, objEvent, outFile
Dim dtmStartDate, dtmEndDate, DateToCheck, fileDate
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
'change the date form "/" to "-" so it can be used in the file name
fileDate = Replace(Date - 7,"/","-")
Set outFile = objFSO.CreateTextFile("D:\" & fileDate & "-Events.txt",True)
DateToCheck = Date - 20
dtmEndDate.SetVarDate Date, True
dtmStartDate.SetVarDate DateToCheck, True
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent where EventCode = '20158' and TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
Function evtdatetime(evttime)
Dim tmGen, dtPart, tmPart
tmGen = Left(evttime, 14)
dtPart = Left(tmGen, 8)
tmPart = Right(tmGen, 6)
'evtdatetime = Mid(dtPart, 2) & "." & Right(dtPart,5, 2) & "." & Left(dtPart, 4) & " " & _
evtdatetime = Right(dtPart, 2) & "." & Mid(dtPart, 5, 2) & "." & Left(dtPart, 4) & " " & _
Left(tmPart, 2) & ":" & Mid(tmPart, 3, 2) & ":" & Right(tmPart, 2)
End Function
For each objEvent in colEvents
outFile.WriteLine evtdatetime(objEvent.TimeWritten) & " " & objEvent.Message
next
outFile.Close
MsgBox "Файл сохранен на диск С:/"