有没有办法验证 Windows 注册表项是否易失 (REG_OPTION_VOLATILE)? [英] Is there a way to verify if a Windows registry key is volatile (REG_OPTION_VOLATILE)?
问题描述
在 Windows 注册表中,密钥可以创建为易失性 - 这意味着易失性密钥不会在 PC 重启后继续存在.重新启动后,注册表中将找不到此类密钥的踪迹.这由 API RegCreateKeyEx 的选项 REG_OPTION_VOLATILE 指定.
In Windows registry the keys can be created as volatile - meaning that a volatile key is not going to survive a PC reboot. After the reboot no trace of such key will be found in registry. This is specified by the option REG_OPTION_VOLATILE of API RegCreateKeyEx.
我需要验证某个 Windows 注册表项是否易失(使用 REG_OPTION_VOLATILE 创建).
I need to verify if a certain Windows registry key is volatile or not (created with REG_OPTION_VOLATILE).
例如,密钥可能位于 (HKLM\Software\MyCompany\MyProgram\KeyToBeChecked) 下.
For example, the key may be located under (HKLM\Software\MyCompany\MyProgram\KeyToBeChecked).
似乎没有允许进行此类检查的直接 WIN API-s.
There seem to be no direct WIN API-s that allow making this sort of check.
有人知道如何检查吗?
推荐答案
一种方法是尝试使用 RegCreateKeyEx
在正在验证的密钥下创建非易失性子密钥.如果密钥确实是易失性的,那么它会失败并显示错误 ERROR_CHILD_MUST_BE_VOLATILE
.甚至 ShSetValue
在尝试设置易失性密钥中的值时也会返回 ERROR_CHILD_MUST_BE_VOLATILE
.
One way is to try creating a non-volatile subkey under the key that's being verified, using RegCreateKeyEx
. If the key is indeed volatile, then it would fail with error ERROR_CHILD_MUST_BE_VOLATILE
. Even ShSetValue
returns ERROR_CHILD_MUST_BE_VOLATILE
while trying to set a value in a volatile key.
这篇关于有没有办法验证 Windows 注册表项是否易失 (REG_OPTION_VOLATILE)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!