无法删除注册表中的值

时间:2017-05-11 09:33:14

标签: vb.net registry visual-studio-2017

我创建了一个注册表项值:

My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "TestApp", "C:\myapp.exe")

工作正常,价值在注册表中。我试图用

删除它
My.Computer.Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run").DeleteValue("TestApp")

My.Computer.Registry.CurrentUser.DeleteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\TestApp")

它不起作用。我收到一个错误:“值不存在”...但该值存在于我的注册表中。

如何删除值(但不是键)?有什么想法吗?

1 个答案:

答案 0 :(得分:0)

如果您需要对密钥的写访问权限,

OpenSubKey设置为true,例如,如果您想要删除值:

Registry.CurrentUser.OpenSubKey(“Software \ Microsoft \ Windows \ CurrentVersion \ Run \”, True )。DeleteValue(“要删除的值”)