隐藏的注册表项/值

Mar*_*rco 6 c# registry

在SO上阅读这篇文章后,我尝试编写一个小应用程序,我需要阅读并编写隐藏的注册表项/值.
使用NT Native API创建"隐藏"注册表值链接检查了Registry Manipulation.
第一个给了我一些工作,但它是用C++编写的,而第二个是Delphi项目运行良好.
我无法先转换,我可以尝试转换第二,但我需要找到一些代码来读取键/值.出于这个原因,我想知道是否有"准备好"并在C#中测试过.
我还下载了Proces Hacker v1.11源代码并使用它来部分转换Delphi示例,如下所示,但隐藏的注册表项是可访问的(而在Delphi中则不是)并且没有API来编写值.

static void Main(string[] args)
{
    string KeyNameBuffer = @"\Registry\User\S-1-5-21-3979903645-2167650815-2353538381-1001\SOFTWARE";
    string NewKeyNameBuffer = "Systems Internals";
    string HiddenKeyNameBuffer = "Can't touch me\0";
    string HiddenValueNameBuffer = "Hidden Value";

    // Apro la chiave di registro
    IntPtr SoftwareKeyHandle = CreateKey(KeyNameBuffer, IntPtr.Zero);
    if (SoftwareKeyHandle != IntPtr.Zero)
    {
        IntPtr SysKeyHandle = CreateKey(NewKeyNameBuffer, SoftwareKeyHandle);
        if (SysKeyHandle != IntPtr.Zero)
        {        
            // This key shouldn't be accessible, but it is            
            IntPtr HiddenKeyHandle = CreateKey(HiddenKeyNameBuffer, SysKeyHandle);
            if (HiddenKeyHandle != IntPtr.Zero)
            {
                // I don't have APIs to write values
            }
        }
    }
}

static IntPtr CreateKey(string keyName, IntPtr rootKey)
{
    IntPtr res;
    KeyCreationDisposition disp;
    ObjectAttributes attributes = new ObjectAttributes(keyName,
        ObjectFlags.CaseInsensitive, 
        new NativeHandle(rootKey));
    NtStatus st = Win32.NtCreateKey(out res, KeyAccess.All, 
        ref attributes, 0, 
        IntPtr.Zero, RegOptions.NonVolatile, out disp);
    return st == NtStatus.Success ? res : IntPtr.Zero;
}
Run Code Online (Sandbox Code Playgroud)

最后:从Vista开始,\Registry\Machine如果您没有以管理员身份运行应用程序,则无法编写部分内容,因此在示例中我使用了我的用户注册表项.如果我需要存储每台机器的值,是否有办法让我们的本机API编写注册表的那一部分?

bun*_*ead 1

如果您希望在 HKLM 中使用它并且权限不允许您使用,那么您使用哪个 API 层、Reg* 函数或 Nt* 函数都没有关系 - 它不会让您在访问被拒绝错误的情况下执行此操作。