const string regWhiteList = @"SOFTWARE\WhiteListManager\WhiteList";
using (var section = Registry.CurrentUser.OpenSubKey(regWhiteList))
{
if (section == null)
return;
foreach (string keyName in section.GetSubKeyNames())
{
var info = Applications.FirstOrDefault(x => x.RegistryKeyName == keyName);
if (info != null)
{
Applications.Remove(info);
WhiteList.Add(info);
}
}
}
private void AddToWhiteList(RegistryUninstallInfo info)
{
Applications.Remove(info);
WhiteList.Add(info);
try
{
using (var section = Registry.CurrentUser.OpenSubKey(regWhiteList))
{
section.CreateSubKey(info.RegistryKeyName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void plus_program_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in Not_white.SelectedRows)
{
object[] items = new object[row.Cells.Count];
for (int i = 0; i < row.Cells.Count; i++)
{
items[i] = row.Cells[i].Value;
}
Yes_white.Rows.Add(items);
Not_white.Rows.Remove(row);
}
}
private void White_Load(object sender, EventArgs e)
{
Applications.Clear();
if (Registry.CurrentUser.OpenSubKey(@"Software\Курсовая\Yes_white") != null && (Registry.CurrentUser.OpenSubKey(@"Software\Курсовая\Not_white")!= null)) //если путь существует
{
SetDoubleBuffered(Yes_white, true);
Yes_white.DataSource = Applications;
Applications.Clear();
var section = Registry.LocalMachine.OpenSubKey(@"Software\Курсовая\Yes_white");
foreach (string keyName in section.GetSubKeyNames())
{
var key = section.OpenSubKey(keyName);
string name = key.GetValue("DisplayName")?.ToString();
if (name != null)
{
Applications.Add(new RegistryUninstallInfo
{
DisplayName = name,
DisplayVersion = key.GetValue("DisplayVersion")?.ToString(),
Publisher = key.GetValue("Publisher")?.ToString(),
});
}
}
SetDoubleBuffered(Not_white, true);
Not_white.DataSource = Applications;
Applications.Clear();
var section2 = Registry.LocalMachine.OpenSubKey(@"Software\Курсовая\Not_white");
foreach (string keyName in section.GetSubKeyNames())
{
var key = section.OpenSubKey(keyName);
string name = key.GetValue("DisplayName")?.ToString();
if (name != null)
{
Applications.Add(new RegistryUninstallInfo
{
DisplayName = name,
DisplayVersion = key.GetValue("DisplayVersion")?.ToString(),
Publisher = key.GetValue("Publisher")?.ToString(),
});
}
}
}
else
{
SetDoubleBuffered(Not_white, true);
Not_white.DataSource = Applications;
Applications.Clear();
var section = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (string keyName in section.GetSubKeyNames())
{
var key = section.OpenSubKey(keyName);
string name = key.GetValue("DisplayName")?.ToString();
if (name != null)
{
Applications.Add(new RegistryUninstallInfo
{
DisplayName = name,
DisplayVersion = key.GetValue("DisplayVersion")?.ToString(),
Publisher = key.GetValue("Publisher")?.ToString(),
});
}
}
}
}