Function Reference


_WinAPI_RegNotifyChangeKeyValue

Notifies the caller about changes to the attributes or contents of a specified registry key

#include <WinAPIReg.au3>
_WinAPI_RegNotifyChangeKeyValue ( $hKey, $iFilter [, $bSubtree = False [, $bAsync = False [, $hEvent = 0]]] )

Parameters

$hKey Handle to an open registry key. The key must have been opened with the KEY_NOTIFY access right.
This handle is returned by the _WinAPI_RegCreateKey() or _WinAPI_RegOpenKey() function. It can also
be one of the following predefined keys:
    $HKEY_CLASSES_ROOT
    $HKEY_CURRENT_CONFIG
    $HKEY_CURRENT_USER
    $HKEY_LOCAL_MACHINE
    $HKEY_USERS
$iFilter Indicates the changes that should be reported.
This parameter can be one or more of the following values:
    $REG_NOTIFY_CHANGE_NAME
    $REG_NOTIFY_CHANGE_ATTRIBUTES
    $REG_NOTIFY_CHANGE_LAST_SET
    $REG_NOTIFY_CHANGE_SECURITY
$bSubtree [optional] Specifies whether report changes in the subkeys of the specified key, valid values:
    True - The function reports changes in the specified key and all its subkeys.
    False - The function reports changes only in the specified key (Default).
$bAsync [optional] Specifies whether return immediately, valid values:
    True - The function returns immediately and reports changes by signaling the specified event.
    False - The function does not return until a change has occurred (Default).
$hEvent [optional] Handle to an event.
If the $fAsync parameter is True, the function returns immediately and changes are reported by signaling this event, otherwise this parameter is ignored (Default).

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.

Remarks

If the specified key is closed, the event is signaled.
This means that an application should not depend on the key being open after returning from a wait operation on the event.

Related

_WinAPI_RegCreateKey, _WinAPI_RegOpenKey

See Also

Search RegNotifyChangeKeyValue in MSDN Library.

Example

#include <APIRegConstants.au3>
#include <Debug.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>
#include <WinAPIReg.au3>

Opt('TrayAutoPause', 0)

Example()

Func Example()
        Local $sKey = 'Software\AutoIt v3'
        Local $hKey = _WinAPI_RegOpenKey($HKEY_CURRENT_USER, $sKey, $KEY_NOTIFY)
        If @error Then
                _DebugSetup(Default, True)
                _DebugReport("! RegOpenKey @error =" & @error & @CRLF & @TAB &_WinAPI_GetErrorMessage(@extended))
                Exit
        EndIf
        Local $hEvent = _WinAPI_CreateEvent()
        If Not _WinAPI_RegNotifyChangeKeyValue($hKey, $REG_NOTIFY_CHANGE_LAST_SET, 0, 1, $hEvent) Then
                Exit
        EndIf

        RegWrite("HKCU\" & $sKey, "text", "REG_DWORD", 1) ; to simulate the change

        While 1
                If Not _WinAPI_WaitForSingleObject($hEvent, 0) Then
                        Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4096, ''Registry'', ''The registry hive has been modified.'' & @CRLF & @CRLF & ''HKEY_CURRENT_USER\Software\AutoIt v3'', 5)"')
                        ExitLoop
                EndIf
                Sleep(100)
        WEnd

        RegDelete("HKCU\" & $sKey, "text")
        _WinAPI_CloseHandle($hEvent)
        _WinAPI_RegCloseKey($hKey)

EndFunc   ;==>Example