从注册表中删除密钥
问题描述:
嘿,我试图从注册表中删除一个密钥,但我似乎无法得到它正确。从注册表中删除密钥
我的代码如下所示:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim tmpKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Dim foundKey As RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey(tmpKey, True)
If Not (foundKey Is Nothing) Then
foundKey.DeleteSubKey("Billy")
Else
MsgBox("not found")
End If
End Sub
的树是这个样子: 1
口口声声说不能找到钥匙...任何帮助将是巨大的。
大卫
答
我相信你正试图在该子项(“运行”),以删除一个值(“比利”)。
如果是的话,你就需要使用DeleteValue()方法,而不是DeleteSubKey的()。
If Not (foundKey Is Nothing) Then
foundKey.DeleteValue("Billy")
Else
MsgBox("not found")
End If
正确,“比利”似乎是子密钥Run中的一个值。所以,你不能使用Delete DeleteSubKey作为值。 +1 @Unomono – Harsh 2012-02-09 06:48:47