根据注册表项的一个值删除注册表项
本文关键字:注册表 一个 删除 | 更新日期: 2023-09-27 17:49:19
我正在开发一个简单的应用程序来从注册表中删除用户配置文件条目,但是我遇到了一个问题。
首先,我通过以下代码获取ProfileList中的所有子键:
List<string> KeyList = new List<string>();
RegistryKey ProfileList = Registry.LocalMachine.OpenSubKey(@"SOFTWARE''Microsoft'Windows NT''CurrentVersion''ProfileList''");
foreach (string ProfileKey in ProfileList.GetSubKeyNames())
{
KeyList.Add(ProfileKey);
}
从那里,我得到每个键的ProfileImagePath值,并将它们添加到一个复选框:
KeyList.ForEach(delegate(string ProfileKey)
{
ProfileList = Registry.LocalMachine.OpenSubKey(@"SOFTWARE''Microsoft'Windows NT''CurrentVersion''ProfileList''" + ProfileKey + "''");
checkedListBox1.Items.Add(ProfileList.GetValue("ProfileImagePath").ToString());
});
然后,当用户单击删除按钮时,我希望应用程序删除选中的用户配置文件。但是,我必须获得每个选中项的值(看起来类似于C:/Users/Name),并确定要删除哪些注册表项。我假设我可以在foreach循环中做到这一点,但我不太确定如何做到。做这件事的最好方法是什么?谢谢。
给你。您可以在用户单击"Delete Selected Users"之类的按钮时执行此代码。下面是代码的外壳:
string[] CheckItemsArray = new string[checkedListBox1.CheckedItems.Count+1];
checkedListBox1.CheckedItems.CopyTo(CheckItemsArray, 0);
foreach (string CheckedItem in CheckItemsArray)
{
if (CheckedItem != null)
{
//your deleting logic here
}
}