public List <INSTALLED> installeds() { Tuple <RegistryHive, RegistryView, string>[] list = { Tuple.Create(RegistryHive.CurrentUser, RegistryView.Registry64, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"), Tuple.Create(RegistryHive.LocalMachine, RegistryView.Registry64, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"), Tuple.Create(RegistryHive.LocalMachine, RegistryView.Registry32, @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") }; List <INSTALLED> installeds = new List <INSTALLED>(); foreach (var item in list) { try { RegistryKey subkey = RegistryKey.OpenBaseKey(item.Item1, item.Item2).OpenSubKey(item.Item3); foreach (string installed in subkey.GetSubKeyNames()) { using (RegistryKey info = subkey.OpenSubKey(installed)) { if (info.GetValue("UninstallString") != null && info.GetValue("DisplayName") != null && !excludePublishers.Any(info.GetValue("DisplayName").ToString().Contains)) { if (info.GetValue("Publisher") == null || !excludePublishers.Contains(info.GetValue("Publisher").ToString())) { INSTALLED soft = new INSTALLED(); soft.name = info.GetValue("DisplayName").ToString(); //Console.WriteLine(soft.name); if (info.GetValue("Publisher") == null) { soft.publisher = null; } else { soft.publisher = info.GetValue("Publisher").ToString(); } string UninstallString = info.GetValue("UninstallString").ToString(); soft.UninstallString = UninstallString; string[] array = UninstallString.Split(new[] { @"\" }, StringSplitOptions.None); string path = UninstallString.Replace(@"\" + array.Last(), ""); soft.path = path; soft.regkey = info.Name; installeds.Add(soft); } } else { continue; } } } } catch { continue; } } return(ListDistinct(installeds)); }
public void uninstall(INSTALLED soft) { string batch = "start \"\" \"" + version + "\" \"" + soft.path + "\" /D /S"; cmd.ExecuteCommand(batch); var reg = new registry(); reg.delete(soft.regkey); }
private void uninstalled_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { int limit = 6; if (e.Action == NotifyCollectionChangedAction.Add) { // scroll the new item into view //listView.ScrollIntoView(e.NewItems[0]); //Console.WriteLine(((INSTALLED)e.NewItems[0]).name); INSTALLED lv_uninstalled_item = ((INSTALLED)e.NewItems[0]); INSTALLEDS.Remove(lv_uninstalled_item); foreach (SHORTCUT item in lv_alllnk.Items) { int diff = LevenshteinDistance.Compute(item.name, lv_uninstalled_item.name); if (diff <= limit) { lv_dellnk.Items.Add(item); break; } } foreach (SHORTCUT item in lv_allstartmenu.Items) { int diff = LevenshteinDistance.Compute(item.name, lv_uninstalled_item.name); if (diff <= limit) { lv_delstartmenu.Items.Add(item); break; } } } else if (e.Action == NotifyCollectionChangedAction.Remove) { INSTALLED lv_uninstalled_item = ((INSTALLED)e.OldItems[0]); INSTALLEDS.Add(lv_uninstalled_item); foreach (SHORTCUT item in lv_dellnk.Items) { int diff = LevenshteinDistance.Compute(item.name, lv_uninstalled_item.name); if (diff < limit) { lv_dellnk.Items.Remove(item); break; } } foreach (SHORTCUT item in lv_delstartmenu.Items) { int diff = LevenshteinDistance.Compute(item.name, lv_uninstalled_item.name); if (diff < limit) { lv_delstartmenu.Items.Remove(item); break; } } } }
public List <INSTALLED> installeds() { var list = new ListWithDuplicates(); list.Add(Registry.CurrentUser, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); list.Add(Registry.LocalMachine, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); list.Add(Registry.LocalMachine, @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); List <INSTALLED> installeds = new List <INSTALLED>(); foreach (var item in list) { RegistryKey subkey = item.Key.OpenSubKey(item.Value); foreach (string installed in subkey.GetSubKeyNames()) { using (RegistryKey info = subkey.OpenSubKey(installed)) { if (info.GetValue("UninstallString") != null && info.GetValue("DisplayName") != null && !excludePublishers.Any(info.GetValue("DisplayName").ToString().Contains)) { if (info.GetValue("Publisher") == null || !excludePublishers.Contains(info.GetValue("Publisher").ToString())) { INSTALLED soft = new INSTALLED(); soft.name = info.GetValue("DisplayName").ToString(); if (info.GetValue("Publisher") == null) { soft.publisher = null; } else { soft.publisher = info.GetValue("Publisher").ToString(); } string UninstallString = info.GetValue("UninstallString").ToString(); soft.UninstallString = UninstallString; string[] array = UninstallString.Split(new[] { @"\" }, StringSplitOptions.None); string path = UninstallString.Replace(@"\" + array.Last(), ""); soft.path = path; soft.regkey = info.Name; installeds.Add(soft); } } else { continue; } } } } return(installeds); }
public void uninstall(INSTALLED soft) { string batch; if (soft.path.Contains("MsiExec")) { soft.path = soft.path.Replace("/I", "/X"); batch = soft.path + " /qn /norestart"; } else { soft.path = soft.path.Replace(@"\\", @"\"); batch = "start \"\" \"" + version + "\" \"" + soft.path + "\" /D /S"; var reg = new registry(); reg.delete(soft.regkey); } //Console.WriteLine(batch); //Console.WriteLine(soft.regkey); cmd.ExecuteCommand(batch); }
public void uninstall(INSTALLED soft) { string batch; if (soft.path.Contains("MsiExec")) { soft.path = soft.path.Replace("/I", "/X"); batch = soft.path + " /qn /norestart"; cmd.ExecuteCommand(batch); } else { if (File.Exists(soft.UninstallString)) { ProcessStartInfo startInfo = new ProcessStartInfo(soft.UninstallString); startInfo.UseShellExecute = true; Process.Start(startInfo); } else { Console.WriteLine(soft.UninstallString + "不存在."); } } }