Windows注册表键监听器无法注册从HKEY_USERS中删除的子键。

huangapple go评论93阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2022年8月4日 05:30:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/73228027.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定