using Microsoft.Win32; //操作注册表需要引用的空间 private void but_Del_Click(object sender, EventArgs e) { //指定路径 RegistryKey key = Registry.LocalMachine; RegistryKey SoftKey = key.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager", true); string[] subkeyNames = SoftKey.GetValueNames(); //取得该项下所有键值的名称的序列,并传递给预定的数组中 foreach (string keyName in subkeyNames) { if (keyName == "PendingFileRenameOperations") //判断键值的名称 { SoftKey.DeleteValue("PendingFileRenameOperations",true); MessageBox.Show("清除SQL挂起成功!"); } } SoftKey.Close(); key.Close(); }