RegNotifyChangeKeyValue stop notifying once the key is deleted?
RegNotifyChangeKeyValue function lets you when when a change occurs to a registry key. But once the key is deleted, the notifications stop. There is no notification if a new key is created with the same name. Why not?
Well, because that’s a new key. It’s not the key that you passed to
The end of a registry key’s lifecycle is its deletion. Once it’s gone, it’s not coming back. Any handle to the registry key is now a zombie. A new registry key be created with the same name as the one that was deleted, but that’s a new key, which is not the same as the key that you were monitoring.
It’s like saying, “You see that house at 123 Main Street? Let me know when ownership of that house changes.” When the house is sold, you get a notification.
And then you get a notification that the house has been demolished.
That’s the last notification you’ll get. If a new house is built at 123 Main Street, you won’t get any notifications about changes in ownership of that house, because that’s not the house that you subscribed to. Your subscription is for the house that was demolished, and it’s still demolished.
(A more mundane example would be monitoring changes in a file. Once the file is deleted, its lifetime is over, and there won’t be any more notifications. If another file is created with the same name, well, it’s nice that it has the same name, but it’s not the same file. It’s a brand new file that happens to have the same name as the old one.)
So what can you do if you want to monitor the new key, too?
Open the new key and call
RegNotifyChangeKeyValue to start monitoring it.
If the new key doesn’t exist yet, you could create it. If you don’t want to create it, but you want to be notified when it is created, then you’ll have to set a notification on its parent (or closest ancestor that exists), watching for creation of subkeys. (You don’t need to watch recursively. You’ll get notified with the direct child key is created, at which point you can find the closest extent ancestor and repeat.)