gpt4 book ai didi

c++ - 确定注册表项是否包含注册表值或子项的最佳方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 15:13:29 27 4
gpt4 key购买 nike

我编写了一个在 Windows 注册表中创建以下子项的程序:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList

我写了第二个程序,它撤销了我第一个程序所做的事情。第二个程序必须在删除子项之前检查该子项是否包含更多子项或值。如果子项不包含其他子项或值,则子项将被删除。

如何检查子项是否包含任何子项或值?

最佳答案

使用RegQueryInfoKey() :

Retrieves information about the specified registry key.

在它可以输出的众多不同参数中,有以下两个对你有用的参数:

lpcSubKeys [out, optional]
A pointer to a variable that receives the number of subkeys that are contained by the specified key. This parameter can be NULL.

lpcValues [out, optional]
A pointer to a variable that receives the number of values that are associated with the key. This parameter can be NULL.

话虽如此,请注意 RegDeleteKey()如果指定的键有任何子键,将失败,但如果它有任何值则不会。所以你真的根本不需要检查子键是否存在,只需要检查值。如果没有值存在,让函数正常失败。

一个更简单的解决方案是使用 SHDeleteEmptyKey()相反,如果键有任何子键或值,它将失败。那么你根本不需要手动检查。

关于c++ - 确定注册表项是否包含注册表值或子项的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44034205/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com