0

I am using vb.net and I want to count values in windows registry key under HKEY_CURRENT_USER\SOFTWARE\MYAPP. Using the code below:

Dim tempKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\MyApp")
Dim count As Integer = tempKey.ValueCount.ToString

but I'm getting an error on the second line saying:

Object reference not set to an instance of an object.

Please I need your help.

Visual Vincent
  • 17,424
  • 5
  • 24
  • 66
Chata
  • 27
  • 1
  • 8
  • Turn on `Option Strict`. If `Count` is an integer, using `ToString` to assign something to it wont compile. If there is no "Software\MyApp" entry, the key will be `Nothing`. Your code doesnt check. – Ňɏssa Pøngjǣrdenlarp Jul 20 '16 at 21:22
  • Your subKey name is probably wrong - use regedit to copy the Key name and remove `HKEY_CURRENT_USER\' BTW please include the Imports statement and any require non-standard references. – rheitzman Jul 20 '16 at 21:52
  • there was no entry under software\MyApp so I changed my code to include the code to check if it is empty. It is working now. Below is the code added: If My.Computer.Registry.CurrentUser.OpenSubKey("Software\MyApp") Is Nothing Then Count=0 Else Dim tempKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\MyApp") Dim count As Integer = tempKey.ValueCount.ToString End If – Chata Jul 20 '16 at 22:07

0 Answers0