有没有办法验证 Windows 注册表项是否易失(REG_OPTION_VOLATILE)?

发布于 2024-10-07 09:45:51 字数 329 浏览 0 评论 0原文

在 Windows 注册表中,密钥可以创建为易失性的 - 这意味着易失性密钥在 PC 重新启动后将无法继续存在。重新启动后,在注册表中将找不到此类密钥的痕迹。 这是由 API RegCreateKeyEx 的选项 REG_OPTION_VOLATILE 指定的。

我需要验证某个 Windows 注册表项是否是易失性的(使用 REG_OPTION_VOLATILE 创建)。

例如,密钥可能位于 (HKLM\Software\MyCompany\MyProgram\KeyToBeChecked) 下。

似乎没有直接的 WIN API 允许进行此类检查。

有谁知道如何检查这一点?

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.

I need to verify if a certain Windows registry key is volatile or not (created with REG_OPTION_VOLATILE).

For example, the key may be located under (HKLM\Software\MyCompany\MyProgram\KeyToBeChecked).

There seem to be no direct WIN API-s that allow making this sort of check.

Does anyone know how this could be checked?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾兮 2024-10-14 09:45:51

一种方法是尝试使用 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.

泅渡 2024-10-14 09:45:51

从win7开始存在未记录的方式 - 需要调用 ZwQueryKeyKeyFlagsInformation。通过这个,我们可以查询键是否易失,也可以 - 键是否是到另一个键的符号链接。代码如下所示:

struct KEY_CONTROL_FLAGS_INFO_W7  // KeyFlagsInformation for Win7
{
    ULONG ControlFlags[3];
};

#define KEY_CTRL_FL_W7_01__IS_VOLATILE                                 0x01
#define KEY_CTRL_FL_W7_01__SYM_LINK                                    0x02


    HKEY hKey;
    LSTATUS r = RegOpenKeyEx(HKEY_CURRENT_USER, 
        L"Volatile Environment", REG_OPTION_OPEN_LINK, KEY_READ, &hKey);
    if (r == NOERROR)
    {
        ULONG cb;
        KEY_CONTROL_FLAGS_INFO_W7 kcf;

        if (0 <= ZwQueryKey(hKey, KeyFlagsInformation, &kcf, sizeof(kcf), &cb))
        {
            if (kcf.ControlFlags[1] & KEY_CTRL_FL_W7_01__IS_VOLATILE)
            {
                DbgPrint("key is volatile\n");
            }

            if (kcf.ControlFlags[1] & KEY_CTRL_FL_W7_01__SYM_LINK)
            {
                DbgPrint("key is link\n");
            }
        }
        RegCloseKey(hKey);
    }

begin from win7 exist undocumented way - need call ZwQueryKey with KeyFlagsInformation. with this we can query are key volatile or not, also - are key is symbolic link to another key. code can look like:

struct KEY_CONTROL_FLAGS_INFO_W7  // KeyFlagsInformation for Win7
{
    ULONG ControlFlags[3];
};

#define KEY_CTRL_FL_W7_01__IS_VOLATILE                                 0x01
#define KEY_CTRL_FL_W7_01__SYM_LINK                                    0x02


    HKEY hKey;
    LSTATUS r = RegOpenKeyEx(HKEY_CURRENT_USER, 
        L"Volatile Environment", REG_OPTION_OPEN_LINK, KEY_READ, &hKey);
    if (r == NOERROR)
    {
        ULONG cb;
        KEY_CONTROL_FLAGS_INFO_W7 kcf;

        if (0 <= ZwQueryKey(hKey, KeyFlagsInformation, &kcf, sizeof(kcf), &cb))
        {
            if (kcf.ControlFlags[1] & KEY_CTRL_FL_W7_01__IS_VOLATILE)
            {
                DbgPrint("key is volatile\n");
            }

            if (kcf.ControlFlags[1] & KEY_CTRL_FL_W7_01__SYM_LINK)
            {
                DbgPrint("key is link\n");
            }
        }
        RegCloseKey(hKey);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文