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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
Option Explicit
'Constantes
Const cstrIntervalle = "2" 'Interval de check en seconde
Const cstrDrive = "C:"
Const cstFolder = "\\scripts\\"
Const cstrComputer = "."
Const cintForReading = 1
'Globale variable
Dim objWMIService,strQuerry,colObjEvents,objFileSystemObject,ObjFile
Dim arrLineValue
'Instancier les objects
Set objWMIService = GetObject( "winmgmts:" & _
"{impersonationLevel=impersonate}!\\" &_
cstrComputer & "\root\cimv2" )
'Creation de la requete de monitoring
strQuerry = "Select * From __InstanceOperationEvent" _
& " Within " & cstrIntervalle _
& " Where Targetinstance Isa 'CIM_DataFile'" _
& " And TargetInstance.Drive='" & cstrDrive & "'"_
& " And TargetInstance.Path='" & cstFolder & "'"
Set colObjEvents = objWMIService.ExecNotificationQuery(strQuerry)
Do
Dim objEvent,objTargetInst
'Attend le déclenchement d'un nouvel evenement
Set objEvent = colObjEvents.NextEvent()
Set objTargetInst = objEvent.TargetInstance
Select Case objEvent.Path_.Class
' If it is file creation or deletion event
' just echo the file name
Case "__InstanceCreationEvent"
WScript.Echo "Created: " & objTargetInst.Name
Set objFileSystemObject = WScript.CreateObject("Scripting.FileSystemObject")
Set ObjFile = objFileSystemObject.OpenTextFile(objTargetInst.Name, cintForReading)
While Not ObjFile.AtEndOfStream
arrLineValue= Split(ObjFile.ReadLine,"=")
If (arrLineValue(0) = "GUID") Then
WScript.Echo "Valeur du GUID: " & arrLineValue(UBound(arrLineValue))
End If
Wend
ObjFile.Close()
If objFileSystemObject.FileExists(objTargetInst.Name) Then
objFileSystemObject.DeleteFile objTargetInst.Name
WScript.Echo objTargetInst.Name
End If
Set objFileSystemObject = Nothing
Set ObjFile = Nothing
Case "__InstanceDeletionEvent"
WScript.Echo "Deleted: " & objTargetInst.Name
'Event Modification d'un fichier.
'Case "__InstanceModificationEvent"
End Select
Set objEvent = Nothing
Set objTargetInst = Nothing
Loop
Set objWMIService = Nothing
Set colObjEvents = Nothing |
Partager