我已将所有启动程序添加到列表框中。当我选择项目并单击按钮时,如何删除选定的注册表项?
列表框代码:
private void starting()
{
RegistryKey HKCU = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
{
foreach (string Programs in HKCU.GetValueNames())
{
startupinfo.Items.Add(Programs);
}
HKCU.Close();
}
RegistryKey HKLM = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
{
foreach (string HKLMPrograms in HKLM.GetValueNames())
{
startupinfo.Items.Add(HKLMPrograms);
}
HKLM.Close();
}
这是我可以逐个文件删除的启动文件夹:(感谢 Rikki-B 帮助我)
private void readfiles()
{
string startfolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
var files = Directory.GetFiles(startfolder).Where(name => !name.EndsWith(".ini"));
foreach (string file in files)
{
startupinfo.Items.Add(System.IO.Path.GetFileName(file));
startupinfoDict.Add(System.IO.Path.GetFileName(file), file);
}
}
这是按钮:
private void DisableBtn_Click(object sender, RoutedEventArgs e)
{
if (startupinfo.SelectedItem != null)
{
string s = startupinfo.SelectedItem.ToString();
if (startupinfoDict.ContainsKey(s))
{
File.Delete(startupinfoDict[s]);
}
}
}
列表框的外观: