Registry class. If key exist

社会主义新天地 提交于 2020-05-17 03:01:01

问题


Im using the Microsoft.Win32.Registry class. Im trying to make a if RegKey exist statement but don't know how

I want something like this:

RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\test");
if(key.keyExist("yourKey")) Console.WriteLine("yourKey exist!");

回答1:


As far as I know, the SubKey is stored in a path in the system.

So you can do something like this to check out if the SubKey exists:

using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\test"))
{
       if (key != null)
       {
            Console.WriteLine("yourKey exist!");
       }
       else
       {
           // e.g. create SubKey
       }
}


来源:https://stackoverflow.com/questions/61259747/registry-class-if-key-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!