如何检查注册表项是否存在? [英] How do I check to see if a registry entry exists?

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

问题描述

我正在尝试查看注册表项是否存在.如果有,我就去做,如果没有,我就做别的事情.我尝试了不同的方法,但到目前为止都没有奏效.

I'm trying to see if a registry key exists. If it does, I do on thing, if not, I do something else. I've tried different things, but so far none have worked.

我试过了:

If My.Computer.Registry.CurrentUser.GetValue("MySubKey", True) Is Nothing Then

此外,我尝试查看 regKey var 是否什么都不是.还有一些我想不起来了.

Also, I've tried to see if regKey var is nothing. And a few others I can't remember.

有什么想法吗?

谢谢

推荐答案

要检查注册表项是否存在,您可以使用此...

To check if a Registry key exists you can use this...

  'Obtain an instance of RegistryKey for the CurrentUser registry root. 
   Dim rkCurrentUser As RegistryKey = Registry.CurrentUser
  ' Obtain the key (read-only) and display it.
   If rkCurrentUser IsNot Nothing Then
      Dim rkTest As RegistryKey = rkCurrentUser.OpenSubKey("MySubKey")

      'Check and make sure we have something...
      If rkTest IsNot Nothing Then
         'You have something then...

         rkTest.Close 'Close it, this is important...
      Else
         'You do not have anything...
      End If 

      rkCurrentUser.Close 'Close this after you are done...
   Else
      'Failed to get instance of registry for the current user...
   End If

还有其他方法,但让我知道这对您有用...

There are other ways as well, but let me know how this works out for you...

这篇关于如何检查注册表项是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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