2012-02-09 157 views
1

嘿,我試圖從註冊表中刪除一個密鑰,但我似乎無法得到它正確。從註冊表中刪除密鑰

我的代碼如下所示:

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

口口聲聲說不能找到鑰匙...任何幫助將是巨大的。

大衛

回答

4

我相信你正試圖在該子項(「運行」),以刪除一個值(「比利」)。

如果是的話,你就需要使用DeleteValue()方法,而不是DeleteSubKey的()。

If Not (foundKey Is Nothing) Then 
    foundKey.DeleteValue("Billy") 
Else 
    MsgBox("not found") 
End If 
+0

正確,「比利」似乎是子密鑰Run中的一個值。所以,你不能使用Delete DeleteSubKey作爲值。 +1 @Unomono – Harsh 2012-02-09 06:48:47