Les Snippets

Connexion

Lecture des enregistrements des journaux d'événements de Windows

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 26/11/2006 11:31:07 et initié par jeanmarc [Liste]
Vue : 6021
Catégorie(s) : API, Système, Class
Langages dispo pour ce code :
- VBScript



Langage : VBScript
Date ajout : 26/11/2006
Posté par jeanmarc [Liste]

'Lecture des enregistrements des journaux d'événements de Windows
'Source originale : Cedric NANA, LABORATOIRE SUPINFO DES TECHNOLOGIES MICROSOFT (Equipe Recherche)
'Publiée le 11/05/2005 http://www.laboratoire-microsoft.org/scripts/14221/
'Descriptif de Win32_NTLogEvent
'http://www.secretswindows.com/index.php?rubrique=scripts&ssrubrique=WMI&page=./scripts/wmi/win32ntlogevent.htm
'
'Selection sur LogFile="Application" ou "System", Type="erreur" et TimeGenerated <= à 15h
'
Option Explicit
'Création fichier resultat pour envoi mail automatisé
Dim resultat : resultat =  "D:\Observateur_événements_" & Replace(Date, "/","-") & ".txt"
Dim Fso      : Set Fso = CreateObject("Scripting.fileSystemObject") 
Dim Rapport  : Set Rapport = Fso.openTextFile(resultat, 2, True) 

Dim strComputer, objWMIServices, objWMIObjectSet, objWMIObject    
strComputer = "." 
Set objWMIServices  = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set objWMIObjectSet = objWMIServices.ExecQuery ("Select * from Win32_NTLogEvent")   

For Each objWMIObject In objWMIObjectSet
If  (objWMIObject.LogFile = "Application" Or  objWMIObject.LogFile = "System") And _
    objWMIObject.Type = "erreur" And _
    DateDiff("h", clair(objWMIObject.TimeGenerated), Now) <= 15 Then 

Rapport.writeLine "----------------------------------------------------"     
Rapport.writeLine "Ordinateur: "               & objWMIObject.ComputerName   
Rapport.writeLine "Observateur d'événements: " & objWMIObject.LogFile 
Rapport.writeLine "----------------------------------------------------" 
Rapport.writeLine "Type: "                     & UCase(Left(objWMIObject.Type,1)) & mid(objWMIObject.Type,2) 
Rapport.writeLine "Date: "                     & clair(objWMIObject.TimeGenerated) 
Rapport.writeLine "Source: "                   & objWMIObject.SourceName 
Rapport.writeLine "ID évén.: "                 & objWMIObject.EventCode  
Rapport.writeLine "Utilisateur: "              & objWMIObject.User  
Rapport.writeLine "Numéro d'enregistrement: "  & objWMIObject.RecordNumber 
Rapport.writeLine "Description: "              &vbCrLf& objWMIObject.Message 
End If
Next
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

Function clair(temps)
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)
 clair = CStr(jour) & "/" & CStr(mois) & "/" & CStr(an) & hhmn
End function

Remarque :
Pour ajouter une entrée d'événement à un fichier journal, utiliser la méthode LogEvent de l'objet Shell.
object.LogEvent(intType, strMessage [,strTarget])

Snippets en rapport avec : Wmi, Ntlogevent, Vbs



Codes sources en rapport avec : Wmi, Ntlogevent, Vbs

{Visual Basic, VB6, VB.NET, VB 2005} EVENTVIEWER - NTLOGEVENT - EXTRACTION INFORMATIONS DU JOURNAL D'OBSERVATION DES EVÉNEMENTS WINDOWS
Ce script testé, sous xp, permet d'extraire les informations du Journal d'événements de Windows, à...

{Visual Basic, VB6, VB.NET, VB 2005} INVENTAIRE FICHIERS SUR SERVER DISTANT OU LOCAL
Suite au topic "http://www.vbfrance.com/infomsg_CREATION-TABLE-MATIERES_888257.aspx#3 de mastere30, ...

{C / C++ / C++.NET} [C/WIN32/WMI]SAVOIR SI UNE CLASSE COM EST INSTALLÉE
Pour répondre à la question d'un boulay (Pas sur CS). Il voulait savoir comment faire pour déterm...

{Visual Basic, VB6, VB.NET, VB 2005} CLASSE POUR CONNECTER/DÉCONNECTER UN LECTEUR RÉSEAU
Cette classe permet de travailler avec les lecteurs réseaux. J'ai utilisé WMI et les API. La...

{Visual Basic, VB6, VB.NET, VB 2005} COMMENT CONTRÔLER TOTALEMENT LES PROCESSUS D'UN PC DISTANT (LISTE, KILL, THREADS, TOUT CE QUE VOUS VOULEZ...)
Bonjour, Voilà une source qui permet de contrôler complètement les processus d'un PC distant ! ...

{Visual Basic, VB6, VB.NET, VB 2005} INFOS WMI DES DISQUES DURS (LIEN LECTEUR LOGIQUE / LECTEUR PHYSIQUE)
Encore un titre obscur... j'ai pas trouvé mieux :p En fait, il s'agit de manipuler WMI (je ne con...

{C / C++ / C++.NET} [WMI][C++][DEV-C++] LECTURES D'INFORMATIONS AVEC WMI SOUS DEVCPP
Lecture d'informations WMI en C++ avec DEVC++. A voir: - plantage avec certains...

{C# / C#.NET} SAVOIR L'ADRESSE PHYSIQUE (MAC) DES CARTES RÉSEAUX DE L'ORDINATEUR
Ce bout de code sert a chercher les adresses physiques (MAC) des cartes réseaux installées sur la ma...

{Visual Basic, VB6, VB.NET, VB 2005} RECHERCHE EXTRÊME OU 5 FAÇONS DE CHERCHER UN FICHIER
C'est parti de mon envie d'expérimenter avec WMI. J'ai bûché avec un exemple en C# de TechHeadBrothe...

{C# / C#.NET} GESTION DES IMPRIMANTES - ADDIN POUR WHS
Cet Addin permet de gérer les imprimantes du Home server. Grâce à cet Add-in vous pouvez : - P...