This code successfully monitors the subdirectory 'Receive' for changes, but it then pops up multiple message boxes (and worse problems when I try to have it do other things). If I monitor a folder on the C drive I do not get these issues. Any suggestions?
Code:
strComputer = "."
strDirToMonitor = "C:\\\\rietest\\\\Receive"
strTime = "5"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN " & strTime & " WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=" & Chr(34) & strDirToMonitor & Chr(34) & "'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
If objLatestEvent.Path_.Class = "__InstanceCreationEvent" Then
MsgBox "File found"
End If
Loop