Function Reference


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]]] )


$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.
$iFilter Indicates the changes that should be reported. This parameter can be one or more of the following values.
$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.


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.


_WinAPI_RegCreateKey, _WinAPI_RegOpenKey

See Also

Search RegNotifyChangeKeyValue in MSDN Library.


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

Opt('TrayAutoPause', 0)

Local $hKey = _WinAPI_RegOpenKey($HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Run', $KEY_NOTIFY)
If @error Then
    MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), @extended, _WinAPI_GetErrorMessage(@extended))
Local $hEvent = _WinAPI_CreateEvent()
If Not _WinAPI_RegNotifyChangeKeyValue($hKey, $REG_NOTIFY_CHANGE_LAST_SET, 0, 1, $hEvent) Then

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\Microsoft\Windows\CurrentVersion\Run'', 5)"')
        If Not _WinAPI_RegNotifyChangeKeyValue($hKey, $REG_NOTIFY_CHANGE_LAST_SET, 0, 1, $hEvent) Then