3

我有一把钥匙

“HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\{4CHJHSDJHSJHDJS-SDGSJAD}”

在我的注册表中。使用

Registry.GetValue("keyname", "valuename", "default value")

我可以检索它的任何值。但我需要检查注册表中是否存在“{4CHJHSDJHSJHDJS-SDGSJAD}”。谁能建议我应该使用什么支票来做到这一点?

4

3 回答 3

7

使用注册表项,您可以尝试使用该OpenSubKey方法获取它。如果返回值为null,则该键不存在。我在这里谈论的是键,而不是值。

在您的示例中,这将归结为:

var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{4CHJHSDJHSJHDJS-SDGSJAD}");
if (key == null)
{
    // Key does not exist
}
else
{
    // Key exists
}
于 2013-04-08T08:51:58.987 回答
3

你试过这个

          using Microsoft.Win32;
          RegistryKey myregistry = Registry.CurrentUser.OpenSubKey("MyKey");
          if (myregistry != null)
          {
           string Value=myregistry.GetValue("ID").ToString();
          }
于 2013-04-08T08:53:39.397 回答
1

Registry.CurrentUser您可以使用然后查询注册表项OpenSubKey

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{4CHJHSDJHSJHDJS-SDGSJAD}");

if (key != null)
{
    // key exists
}
else
{
    // key does not exists
}
于 2013-04-08T08:54:48.307 回答