4

I am trying to uninstall a program with a C# application and everything works except the program is still listed in the Control Panel Programs & Features.

It also does this when I uninstall from the command line using wmic.

The program is uninstalled, but I still have to actually click the name in control panel programs & features for a window to pop up and tell me it has uninstalled. After that, it is gone for good. How can I bypass having to go into control panel to completely remove it. I need it to be uninstalled and not listed in control panel.

This is my code to uninstall which appears to be correct:

string programName = "myProgram";
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_Product");

foreach (ManagementObject mo in mos)
{
    if (mo["name"].ToString().Contains(programName))
    {
        mo.InvokeMethod("Uninstall", null);
        MessageBox.Show(mo["name"].ToString() + " uninstalled");
    }
}
SQlBeginner
  • 65
  • 3
  • 9
  • 1
    Maybe you need to delete a Registery Key (in regedit): [link](http://www.cknow.com/cms/articles/how-do-i-remove-addremove-programs-entries.html) – Odrai Mar 05 '15 at 18:22
  • Another possibility is that the installed application has a misconfigured installation (setup). Please read: [link](https://msdn.microsoft.com/en-us/library/aa368032(v=vs.85).aspx) – Odrai Mar 05 '15 at 18:25
  • Assuming the uninstall really works, is this one of those cases where you need to refresh the list of installed programs (F5 key) before it goes away? Sometimes a non-UI install needs that. – PhilDW Mar 05 '15 at 19:23
  • Did you log and read the uninstall? – Christopher Painter Mar 06 '15 at 15:14
  • Does the entry go away when you uninstall the software regularly in the Control Panel? If it does, the uninstaller seems to work correctly. In that case refreshing the list (F5) should succeed. I wouldn't recommend modifying the registry yourself, as that should not be necessary if the uninstaller works. – Thorsten Dittmar Aug 23 '16 at 14:25
  • Did you try a reboot after the uninstall completed? There might be a pending update for the add/remove applet that doesn't happen until you reboot. You could be maintaining links to add/remove if garbage collection doesn't release the mos object from your code. – Stein Åsmul Aug 28 '16 at 17:43

1 Answers1

-1

Check the log for uninstall and if the it is successful and even after a refresh i.e. F5 the entry is still present in Control Panel, for the product which is to be uninstalled delete the registry entry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

Aakash
  • 9
  • 4
  • Removing the registry key yourself is not very good advice. If the application is installed using a proper setup, the setup should remove the registry entry. If it does not this is a sign that the uninstaller does not properly work. – Thorsten Dittmar Aug 23 '16 at 14:23
  • Agreed! It is the installer/setup's job to remove the registry on successful uninstall. There has to be something wrong with the setup if this keeps occurring but I mentioned this solution as a last resort! – Aakash Aug 24 '16 at 07:13