1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
'Lecture des enregistrements des journaux d'événements de Windows
On Error Resume Next
'Création fichier resultat
Dim resultat : resultat = "\\machine_unix\rapport_sauvegarde\rapport_" & wscript.arguments(0) & ".txt"
Dim Fso : Set Fso = CreateObject("Scripting.fileSystemObject")
Dim Rapport : Set Rapport = Fso.openTextFile(resultat, 2, True)
Dim strComputer, objWMIServices, objWMIObjectSet, objWMIObject
strComputer = "machine_windows"
Set objWMIServices = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objWMIObjectSet = objWMIServices.ExecQuery _
("Select * from Win32_NTLogEvent Where LogFile='Application'And Category='3' ")
For Each objWMIObject In objWMIObjectSet
If DateDiff("h", clair(objWMIObject.TimeGenerated),now ) <= 24 Then
Rapport.writeLine " " & objWMIObject.Message
Rapport.writeLine "FINLOG"
End If
Next
Rapport.Close
Set Rapport = Nothing
Set fso = Nothing : Set Rapport = Nothing
Set objWMIObjectSet = Nothing : Set objWMIServices = Nothing
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
WshShell.Run resultat
Set WshShell = Nothing
WScript.Quit
Function clair(temps)
'tranformation de la date "aaaammjjhhmnss" en jj/mm/aaaa hh:mn
Dim debut, an, mois, jour, hhmn
debut = left(temps,8)
an = left(debut,4)
mois = mid(debut,5,2)
jour = right(debut,2)
hhmn = " " & Mid(temps,9,2) & ":" & Mid(temps,11,2) & ":" & Mid(temps,13,2)
clair = CStr(mois) & "/" & CStr(jour) & "/" & CStr(an) & CStr(hhmn)
'MsgBox temps &vbCrLf& clair
End function |
Partager