我可以使用Microsoft.Win32.Registry类获取/设置注册表值。例如,
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获取更多信息。
Registry.CurrentUser
RegistryKey.OpenSubKey
RegistryKey.DeleteValue