注册表类.如果密钥存在 [英] Registry class. If key exist

查看:70
本文介绍了注册表类.如果密钥存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Microsoft.Win32.Registry 类.我试图制作一个RegKey存在语句,但不知道如何

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

我想要这样的东西:

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

推荐答案

据我所知,SubKey存储在系统的路径中.

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

因此,您可以执行以下操作来检查SubKey是否存在:

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
       }
}

这篇关于注册表类.如果密钥存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆