RegNotifyChangeKeyValue - Watch Windows RegistryKey Changes

RegNotifyChangeKeyValue() - Notifies the caller about changes to the attributes or contents of a specified registry key.

Sampl Code:

// Helper function
void RegWatchOut( HANDLE& hEvent )
{
const DWORD dwEventFilter = REG_NOTIFY_CHANGE_NAME
REG_NOTIFY_CHANGE_ATTRIBUTES
REG_NOTIFY_CHANGE_LAST_SET
REG_NOTIFY_CHANGE_SECURITY;

RegNotifyChangeKeyValue( HKEY_LOCAL_MACHINE,
TRUE,
dwEventFilter,
hEvent,
TRUE );
}

int main( int argc, char* argv[] )
{
HANDLE hEvent = CreateEvent( NULL, FALSE, FALSE, NULL );

// Call for notification
RegWatchOut( hEvent );

// Keep looping for ever
for( int Index = 1; WaitForSingleObject( hEvent, INFINITE ) != WAIT_FAILED; ++Index )
{
printf( "Key changed %d time(s)\\n", Index );

// Keep watching, we have to call again for further notifications
RegWatchOut( hEvent );
}

CloseHandle( hEvent );
return 0;
}// End main


References:

http://msdn.microsoft.com/en-us/library/ms724892.aspx

Hacking Windows Registry -
http://ebooks.allfree-stuff.com/eBooks_down/Hacking/Hacking%20the%20Windows%20Registry.pdf

http://nibuthomas.com/2007/09/07/watching-out-for-registry-key-changes-using-regnotifychangekeyvalue/

The Windows Access Control Model Part 1 - http://www.codeproject.com/KB/winsdk/accessctrl1.aspx

The Windows Access Control Model Part 2 – http://www.codeproject.com/KB/winsdk/accessctrl2.aspx

The Windows Access Control Model Part 3 – http://www.codeproject.com/KB/system/accessctrl3.aspx

The Windows Access Control Model Part 4 - http://www.codeproject.com/KB/winsdk/accessctrl4.aspx