/* Removes a package. */ public static bool remove(Package package) { RegistryKey uninstall = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", false); foreach(string key in uninstall.GetSubKeyNames()) if(key == package.Name) { RegistryKey target = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + key, false); try { Process.Start((string)target.GetValue("UninstallString")); } catch(Exception) { return false; } return true; } return false; }
private void PackageForm_Load(object sender, EventArgs e) { if(!engine.IsPackage(package)) { MessageBox.Show("That's not a package."); Dispose(); } selectedPackage = engine.GetPackage(package); status = engine.GetStatus(selectedPackage); switch(status) { case Engine.PackageStatus.NEWER: button1.Text = "Upgrade"; break; case Engine.PackageStatus.NOT_INSTALLED: button1.Text = "Install"; break; default: // INSTALLED, OLDER button1.Text = "Remove"; break; } dataGridView1.AutoGenerateColumns = false; dataGridView1.CellDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellContentDoubleClick); PackageForm.MakeRow(dataGridView1, selectedPackage); }
private void AddPackage(Package[] packages, ListBox listbox) { foreach(Package p in packages) listbox.Items.Add(p.Name); }
/* Returns the status of package relatives to system. */ public PackageStatus GetStatus(Package package) { RegistryKey uninstall = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", false); foreach(string key in uninstall.GetSubKeyNames()) if(key == package.Name) return PackageStatus.INSTALLED; return PackageStatus.NOT_INSTALLED; }