The monitored events are:
* FILE_NAME
* DIR_NAME
* ATTRIBUTES
* SIZE
* LAST_WRITE
* SECURITYnote: further information can be found at MSDN
#Persistent OnExit, HandleExit ; note: event(s) can be present in any combination FindFirstChangeNotification( "testdir", true, "FILE_NAME|DIR_NAME|ATTRIBUTES|SIZE|LAST_WRITE|SECURITY", handles, array_handles ) SetTimer, timer_DetectChange, 1000 return HandleExit: FindCloseChangeNotification( handles ) ExitApp timer_DetectChange: loop, { index := WaitForMultipleObjects( array_handles ) if ( index >= 1 and index <= 6 ) { ; note: index number correlates with order of event present during call ; to FindFirstChangeNotification if ( index = 1 ) MsgBox, change has been detected: FILE_NAME else if ( index = 2 ) MsgBox, change has been detected: DIR_NAME else if ( index = 3 ) MsgBox, change has been detected: ATTRIBUTES else if ( index = 4 ) MsgBox, change has been detected: SIZE else if ( index = 5 ) MsgBox, change has been detected: LAST_WRITE else if ( index = 6 ) MsgBox, change has been detected: SECURITY FindNextChangeNotification( handles, index ) } else break } return EncodeInteger( p_value, p_size, p_address, p_offset ) { loop, %p_size% DllCall( "RtlFillMemory" , "uint", p_address+p_offset+A_Index-1 , "uint", 1 , "uchar", ( p_value >> ( 8*( A_Index-1 ) ) ) & 0xFF ) } ; return value: true = success, false = failure FindFirstChangeNotification( p_path, p_recurse, p_events, byref r_handles, byref r_array_handles ) { r_handles= VarSetCapacity( r_array_handles, 25, 0 ) count = 0 loop, parse, p_events, | { count++ if ( A_LoopField = "FILE_NAME" ) event = 1 else if ( A_LoopField = "DIR_NAME" ) event = 2 else if ( A_LoopField = "ATTRIBUTES" ) event = 4 else if ( A_LoopField = "SIZE" ) event = 8 else if ( A_LoopField = "LAST_WRITE" ) event = 0x10 else if ( A_LoopField = "SECURITY" ) event = 0x100 h_notification := DllCall( "FindFirstChangeNotification", "str", p_path, "int", p_recurse, "uint", event ) if ( ErrorLevel or h_notification = -1 ) { MsgBox, [FindFirstChangeNotification] failed: EL = %ErrorLevel% ~ h_notification = %h_notification% return, false } r_handles = %r_handles%|%h_notification% EncodeInteger( h_notification, 4, &r_array_handles, 1+( A_Index-1 )*4 ) } r_handles = %r_handles%| EncodeInteger( count, 1, &r_array_handles, 0 ) return, true } ; return value: true = success, false = failure FindNextChangeNotification( p_handles, p_index ) { StringGetPos, ix, p_handles, |, L%p_index% StringMid, handle, p_handles, ix+2, InStr( p_handles, "|", true, ix+2 )-( ix+2 ) return, DllCall( "FindNextChangeNotification", "uint", handle ) } ; return value: true = success, false = failure FindCloseChangeNotification( p_handles ) { StringMid, p_handles, p_handles, 2, StrLen( p_handles )-2 result := true loop, parse, p_handles, | result := result && DllCall( "FindCloseChangeNotification", "uint", A_LoopField ) return, result } ; return value: [1,6], otherwise failure WaitForMultipleObjects( byref r_array_handles ) { result := DllCall( "WaitForMultipleObjects", "uint", *( &r_array_handles ), "uint", &r_array_handles+1, "int", false, "uint", 0 ) if ( result >= 0 and result < 6 ) return, result+1 else return, result }