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 63 64 65 66 67 68 69 70
| Option Explicit
Dim fso,Message,Message2,Msg,intInterval,strDrive,strFolder,strComputer,objWMIService,strQuery
Dim colEvents,objEvent,objTargetInst,objPrevInst,objProperty,ws,LOG_FILE_PATH,LogFile,Chemin
Set fso = CreateObject("Scripting.FileSystemObject")
Chemin = Parcourir_Dossier()
'****************************************************************************************************
Function Parcourir_Dossier()
Dim ws,objFolder,Copyright
Copyright = "[ © Hackoo © 2014 ]"
Set ws = CreateObject("Shell.Application")
Set objFolder = ws.BrowseForFolder(0,"Veuillez choisir un dossier pour la surveillance "_
& Copyright,1,"c:\Programs")
If objFolder Is Nothing Then
Wscript.Quit
End If
Parcourir_Dossier = objFolder.self.path
end Function
'****************************************************************************************************
Chemin = Split(fso.GetAbsolutePathName(Chemin),":")
strDrive = Chemin(0) & ":"
strFolder = Replace(Chemin(1), "\", "\\")
If Right(strFolder, 2) <> "\\" Then strFolder = strFolder & "\\"
strComputer = "."
Set ws = CreateObject("WScript.Shell")
LogFile = Left(Wscript.ScriptName,InstrRev(Wscript.ScriptName, ".")) & "log"
LOG_FILE_Path = ws.ExpandEnvironmentStrings("%AppData%") & "\" & LogFile
intInterval = "2"
'Connexion au WMI
Set objWMIService = GetObject( "winmgmts:" &_
"{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\cimv2" )
'La chaîne de la requête
strQuery = _
"Select * From __InstanceOperationEvent" _
& " Within " & intInterval _
& " Where Targetinstance Isa 'CIM_DataFile'" _
& " And TargetInstance.Drive='" & strDrive & "'"_
& " And TargetInstance.path='" & strFolder & "'"
'Exécutez la requête
Set colEvents = _
objWMIService.ExecNotificationQuery(strQuery)
Do
Set objEvent = colEvents.NextEvent()
Set objTargetInst = objEvent.TargetInstance
Select Case objEvent.path_.Class
'Si c'est le cas de la création de fichier ou d'un événement de suppression et afficher
'juste le nom du fichier
Case "__InstanceCreationEvent"
Message = DblQuote(objTargetInst.Name) & " est crée !"
Message2 = String(10,"*") & Now & String(10,"*") & vbCrLf & Message & vbCrLf & String(70,"*")
Call Log(LOG_FILE_Path,Message2)
MsgBox Message2,VbInformation,Message
End Select
Loop
'**********************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub Log(strLogFileChemin,strLogContent)
Const APPEND = 8
Dim objFso,objLogFile
Set objFso = CreateObject("Scripting.FileSystemObject")
If Not objFso.FileExists(strLogFileChemin) Then objFso.CreateTextFile(strLogFileChemin, True).Close
Set objLogFile = objFso.OpenTextFile(strLogFileChemin,APPEND)
objLogFile.WriteLine strLogContent
objLogFile.Close
End Sub
'********************************************************************************************** |
Partager