我可以使用Microsoft.Win32.Registry类获取/设置注册表值。例如,如何删除C#中的注册表值
Microsoft.Win32.Registry.SetValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",
"MyApp",
Application.ExecutablePath);
但我无法删除任何值。我如何删除注册表值?
我可以使用Microsoft.Win32.Registry类获取/设置注册表值。例如,如何删除C#中的注册表值
Microsoft.Win32.Registry.SetValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",
"MyApp",
Application.ExecutablePath);
但我无法删除任何值。我如何删除注册表值?
要删除你的问题设置的值:
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.CurrentUser
,RegistryKey.OpenSubKey
和RegistryKey.DeleteValue
获取更多信息。
RegistryKey registrykeyHKLM = Registry.LocalMachine;
string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Run\MyApp";
registrykeyHKLM.DeleteValue(keyPath);
registrykeyHKLM.Close();
非工作代码 – 2010-03-16 13:13:50
要删除树(〜递归)的所有子项/值,下面是我使用的扩展方法:
public static void DeleteSubKeyTree(this RegistryKey key, string subkey,
bool throwOnMissingSubKey)
{
if (!throwOnMissingSubKey && key.OpenSubKey(subkey) == null) { return; }
key.DeleteSubKeyTree(subkey);
}
用法:
string keyName = @"Software\Microsoft\Windows\CurrentVersion\Run";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true))
{
key.DeleteSubKeyTree("MyApp",false);
}
如何删除整个文件夹?假设我想删除`@“Software \ TeamViewer”;` – 2012-01-03 13:34:28