小编典典

如何在C#中删除注册表值

c#

我可以使用Microsoft.Win32.Registry类获取/设置注册表值。例如,

Microsoft.Win32.Registry.SetValue(
    @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",
    "MyApp", 
    Application.ExecutablePath);

但是我无法删除任何值。如何删除注册表值?


阅读 735

收藏
2020-05-19

共1个答案

小编典典

要删除问题中设置的值:

string keyName = @"Software\Microsoft\Windows\CurrentVersion\Run";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
{
    if (key == null)
    {
        // Key doesn't exist. Do whatever you want to handle
        // this case
    }
    else
    {
        key.DeleteValue("MyApp");
    }
}

看看文档进行Registry.CurrentUserRegistryKey.OpenSubKeyRegistryKey.DeleteValue获取更多信息。

2020-05-19