Search code examples
vb.netregistry

Can i clear value data of default value in subregistry?


I tried using this code to reasign nothing to the default value after I assigned its value = "abc", but I got an error that I couldn't assign null to the default value. Can i do this?

Using k As Microsoft.Win32.RegistryKey = reg.OpenSubKey(path, True)
        'k?.SetValue(vbNullString, vbNullString)
        k.DeleteValue("")
End Using

enter image description here


Solution

  • It's just a silly thing, you have to specify null (Nothing) instead of an empty string (or (Default) or Default, which is what usually comes to mind until you read RegistryKey.GetValueNames() and it appears to be an empty string :)

    Using k As Microsoft.Win32.RegistryKey = reg.OpenSubKey(path, True)
        ' Set a Value
        k.SetValue(Nothing, "New Value")
    
        ' Or delete the current value
        k.DeleteValue(Nothing)
    End Using