Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#注册表项分配为空_C# - Fatal编程技术网

C#注册表项分配为空

C#注册表项分配为空,c#,C#,我正忙着为我自己和其他人创建一个小应用程序,但我有点被困在这里 我想获取带有路径的寄存器“regedit”的值。但是,即使从regedit is复制路径,值“RegistryKey”也始终为空 private bool HasKey { get { try { string path = @"Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlS

我正忙着为我自己和其他人创建一个小应用程序,但我有点被困在这里

我想获取带有路径的寄存器“regedit”的值。但是,即使从regedit is复制路径,值“RegistryKey”也始终为空

private bool HasKey
    {
        get
        {
            try
            {
                string path = @"Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0002";
                using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(path, false))
                {
                    if(key != null)
                    {
                        return true;
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex);
                return false;
            }

            return false;
        }
    }
我只想写一个布尔函数,证明他找到了键。。但是变量“key”总是空的。

试试这个

string path = @"\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0002";
using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
    using (var subKey = key.OpenSubKey(path, false))
    {
        if (subKey != null)
        {
            return true;
        }
    }
}

您试过调试它什么?您的路径是否应该从
\SYSTEM
开始,因为您正在以
RegistryHive.LocalMachine
的子键打开它?谢谢您的回答-James Thrope!!!!我不知道我真的这么做了:3谢谢你帮助我,但有人找到了答案。。但是也试过了,效果很好。。无论如何,祝你有一个美好的一天!!!