For some reason, on the line where I try to set the value of the key, I get the following error:

Object reference not set to an instance of an object

vb Code:
  1. Private Sub writeToKey(ByVal regValue As String)
  2.         Dim regkey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
  3.         regkey.SetValue("Device", regValue, RegistryValueKind.String) 'error occurs here
  4.         regkey.Close()
  5.     End Sub

What am I doing wrong?