如何删除在C#中的注册表值 [英] How to delete a registry value in C#

查看:126
本文介绍了如何删除在C#中的注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can get/set registry values using the Microsoft.Win32.Registry class. For example,

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

但我不能删除任何价值。如何删除注册表值?

But I can't delete any value. How do I delete a registry value?

推荐答案

要删除你的问题设置的值:

To delete the value set in your question:

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");
    }
}

看的文档的<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.currentuser.aspx\"><$c$c>Registry.CurrentUser, RegistryKey.OpenSubKey 和<一个href=\"http://msdn.microsoft.com/en-us/library/dk8b3th2.aspx\"><$c$c>RegistryKey.DeleteValue获取更多信息。

Look at the docs for Registry.CurrentUser, RegistryKey.OpenSubKey and RegistryKey.DeleteValue for more info.

这篇关于如何删除在C#中的注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆