我有一個惱人的問題。 我正在嘗試使用RegDeleteKey值API刪除註冊表值(無我的名字空間),但只做了一處修改。 我希望函數有一個絕對路徑作爲參數。 因此,像這樣:註冊表刪除值
RegDeleteKeyValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","myValue")
大氣壓它看起來像這樣(這一件作品,但沒有絕對路徑作爲參數,如它應該是):
Private Enum RegHive
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_CURRENT_CONFIG = &H80000005
End Enum
RegDeleteKeyValue(Reghive.HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Run","Myvalue")
我試了一下修改像這樣的函數,所以參數將只是絕對路徑和註冊表值。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DeleteReyKeyValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "123")
End Sub
Public Shared Function DeleteReyKeyValue(ByVal Key As String, ByVal valueName As String) As Long
Dim Handle As IntPtr
Dim Hive As String = Split(Key, "\")(0)
Select Case Hive
Case "HKEY_CLASSES_ROOT"
Handle = CType(&H80000000, IntPtr)
Case "HKEY_CURRENT_USER"
Handle = CType(&H80000001, IntPtr)
Case "HKEY_LOCAL_MACHINE"
Handle = CType(&H80000002, IntPtr)
Case "HKEY_USERS"
Handle = CType(&H80000003, IntPtr)
Case "HKEY_CURRENT_CONFIG"
Handle = CType(&H80000005, IntPtr)
End Select
Key = Key.Replace(Hive, String.Empty)
Return RegDeleteKeyValue(Handle, Key, valueName)
End Function
<DllImport("advapi32.dll")> _
Private Shared Function RegDeleteKeyValue(ByVal handle As IntPtr, ByVal keyName As String, ByVal valueName As String) As Long
End Function
當使用這個,沒有任何反應,沒有錯誤,但註冊表值不會被刪除? ; O 這是爲什麼?