英文:
Windows registry key listener is not registering subkeys removed from HKEY_USERS
问题
我正在使用Go语言的windows包,具体是使用windows.RegNotifyChangeKeyValue()函数:
for {
err := windows.RegNotifyChangeKeyValue(
windows.Handle(key),
false,
windows.REG_NOTIFY_CHANGE_LAST_SET|windows.REG_NOTIFY_CHANGE_NAME,
windows.Handle(0),
false,
)
// 当事件触发时执行操作
...
}
然而,当从HKEY_USERS中删除子键时,我没有收到任何事件。如果我监视其他键,当添加或删除子键时,我会收到事件。但是当我监视HKEY_USERS时,只有在添加键时才会收到事件。
为什么在这种情况下HKEY_USERS如此特殊?
编辑:看起来这是因为通过RegLoadKey()和RegUnLoadKey()添加/删除HKEY_USERS的子键。所以我的问题变成了:如何监听RegUnLoadKey()的事件?为什么通过RegLoadKey()添加键会触发事件,但通过RegUnLoadKey删除键却不会触发事件?
英文:
I'm using Go's windows package, specifically the windows.RegNotifyChangeKeyValue() function:
for {
err := windows.RegNotifyChangeKeyValue(
windows.Handle(key),
false,
windows.REG_NOTIFY_CHANGE_LAST_SET|windows.REG_NOTIFY_CHANGE_NAME,
windows.Handle(0),
false,
)
// do stuff once event triggers
...
}
However, I'm not getting any events when a subkey is removed from HKEY_USERS. If I monitor some other key, I get an event when a subkey is added or removed. But when I monitor HKEY_USERS, I only get an event when a key is added.
What makes HKEY_USERS so special in this case?
EDIT: It seem like this is because subkeys of HKEY_USERS are added/removed via RegLoadKey() and RegUnLoadKey(). So my question becomes: how do you listen for events from RegUnLoadKey()? And why does adding keys via RegLoadKey() trigger an event, but removing keys via RegUnLoadKey does not?
答案1
得分: 2
使用RegNotifyChangeKeyValue文档示例中的HKU .DEFAULT命令参数,我无法复现这种行为。在**.DEFAULT**下添加或删除的键和值都会触发事件。
英文:
Using RegNotifyChangeKeyValue document example with HKU .DEFAULT command parameters, I cannot reproduce the behavior. Both Key and Value which are added or deleted under .DEFAULT will signal the event.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论