TUTOS.EU

Créer un événement de déclenchement personnalisé dans le planificateur de tâches

Créer un custom trigger dans le task scheduler d'un Windows 2008

Collez votre requête XML ici :

Voici un exemple de filtre XML pour déclencher sur les events de sécurité 13824 et 13826

<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and ( Task = 13824 or Task = 13826 )]]</Select>
  </Query>
</QueryList>
Lien vers le fichier : cliquez ici Copier le code

Vous pouvez alors vous servir de ces évènements pour déclencher un vbscript qui enverra un email. Exemple de VbScript :

Option Explicit

Dim varSMTPRelay 'Adresse du serveur de messagerie / relais smtp 
Dim varDestEmail, varSujetMail, varMessageMail, varSenderMail, varAttachment
Dim objMessage
Dim WSHShell, vCOMPUTERNAME, Commande
Dim CheminScriptActuel, Chemin
Dim MyDay, MyMonth, ActualDay, varTime
Dim objFSO

varSMTPRelay = "NomServeurRelaiSMTP"
varDestEmail = "AdresseMail01@mail.com;AdresseMail02@mail.com"
varSenderMail = "Sender@mail.com"

MyDay = Day(Now)
MyMonth = Month(Now)

varTime = Time
varTime = Replace(varTime, ":", "-") 'Remplacement des : par - car : est un caractère interdit dans les noms de fichiers

If Len(MyDay) = 1 Then MyDay = "0" & MyDay
If Len(MyMonth) = 1 Then MyMonth = "0" & MyMonth
ActualDay = Year(Now) & "-" & MyMonth & "-" & MyDay


CheminScriptActuel = Left(wscript.scriptfullname,Len(wscript.scriptfullname)-Len(wscript.scriptname)-1)
varAttachment = CheminScriptActuel & "\ExportLog_" & ActualDay & "_" & varTime & ".txt"


Set WSHShell = CreateObject("WScript.Shell")
vCOMPUTERNAME = WSHShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

Commande = """%programfiles(x86)%\Log Parser 2.2\LogParser.exe"" ""SELECT ComputerName , TimeGenerated , EventID , EventCategory , EventTypeName , Message INTO """ & varAttachment & """ FROM \\localhost\Security WHERE EventCategory IN (13824;13826) AND TimeGenerated < '" & ActualDay & " 23:59:59' AND TimeGenerated > '" & ActualDay & " 00:00:00'"" -o:TSV"
WSHShell.Run Commande, 8, true
Set WSHShell = Nothing

varSujetMail = "Modification de droits détecté sur " & vCOMPUTERNAME
varMessageMail = "Des droits ont été modifiés sur " & vCOMPUTERNAME & VbCrLf & "Consultez la pièce attachée pour le détail, elle contient l'extract de cette journée."

Set objMessage = CreateObject("CDO.Message")
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = varSMTPRelay
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update

objMessage.Subject = varSujetMail
objMessage.Sender = varSenderMail
objMessage.To = varDestEmail
objMessage.TextBody = varMessageMail

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(varAttachment) Then 'Si il y a un fichier à mettre en pièce attachée
	objMessage.AddAttachment varAttachment
End If
Set objFSO = Nothing

objMessage.Send

Set objMessage = Nothing
Lien vers le fichier : cliquez ici Copier le code

2