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