Link to home
Create AccountLog in
Avatar of NewsInternationalLtd
NewsInternationalLtd

asked on

How do I delete a VALUE NAME from the registry?

I need to be able to delete a value name from the registry in VB.NET but there appears to be no provision for this, with only DELETEVALUE, DELETESUBKEY or DELETESUBKEYTREE available.
The attached code cycles through a regisrty subkey looking at the value names and uses DELETEVALUE to try and delete one of the value names if it finds a match to a label I have on the form. Unfortunately this just results in an exception saying the value doesn't exist.  Can anyone suggest a way around this for me?

Thank you

Simon
Dim R2 As Microsoft.Win32.RegistryKey = Registry.CurrentUser.OpenSubKey("Software\test\ProxyAdmin")
Dim a2() As String = R2.GetValueNames
 
For i = 0 To a2.GetUpperBound(0)
    If R2.GetValueNames(i) = lblProxy1.Text Then My.Computer.Registry.CurrentUser.DeleteValue("Software\test\ProxyAdmin\" & lblProxy1.Text)
Next
For i = 0 To a2.GetUpperBound(0)
   ComboBox1.Items.Add(R2.GetValueNames(i))
Next

Open in new window

Avatar of VBRocks
VBRocks
Flag of United States of America image

My.Computer.Registry.CurrentUser().DeleteSubKey("Software\_DeleteMe")



What is the text in lblProxy1.Text?

Avatar of NewsInternationalLtd
NewsInternationalLtd

ASKER

lblProxy1.Text is the valuename itself whivh I would like to delete.
Wouldn't the code above just delete the key?
Here you go.  This worked perfect for me:

        Dim key As Microsoft.Win32.RegistryKey = _
            My.Computer.Registry.CurrentUser.OpenSubKey("Software\_DeleteMe2", True)

        key.DeleteValue("DeleteThisValue")
        key.Close()

ASKER CERTIFIED SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks, worked a treat.