Click here to Skip to main content
14,427,291 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to Uninstall application(or program) from control panel on button click. i want to uninstall application from system on button click in c# window application. how can i do this.please hlep me by giving any idea or link.........thanks in advance
Posted
Comments
[no name] 27-Aug-12 9:09am
   
Get the uninstall string from the registry and and use that.
Dasaradhi_r 31-Aug-12 10:06am
   
Is your problem resolved?
pradeep rasara 1-Sep-12 0:53am
   
yes thanx....
Rate this:
Please Sign up or sign in to vote.

Solution 1

Each application should have an uninstall command that you can run. It will be located in the registry. Here is a Stack Overflow question that will give you the details on how to do it exactly:

http://stackoverflow.com/questions/450027/uninstalling-an-msi-file-from-the-command-line-without-using-msiexec[^]

Once you know how to do this, it is simply a matter of writing the C# code to make that command line call.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

In Your button click event use the below code:
One Caveat: In 32-bit os, the code can be used as it is but in a 64-bit os,
you have to set the 'Target CPU' to x86 (instead of AnyCPU).

RegistryKey rgKey = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
        ProcessStartInfo info = new ProcessStartInfo();
        Process uninstallProcess = new Process();
        var ns = rgKey.GetSubKeyNames().Where(n => n.ToLower().Contains("cricket"));
        if(ns.Count() > 0)
        {
        foreach (var vsKey in rgKey.GetSubKeyNames())
        {
            RegistryKey productKey = rgKey.OpenSubKey(vsKey);
            string dispName = Convert.ToString(productKey.GetValue("DisplayName"));
            string uninstlString = Convert.ToString(productKey.GetValue("UninstallString"));

            if (dispName.ToLower().Contains("cricket")) //Put the name of the Application you want to uninstall here
            {
                string prdctId = uninstlString.Substring((uninstlString.IndexOf("{")));
                uninstallProcess.StartInfo.FileName = "MsiExec.exe";
                uninstallProcess.StartInfo.Arguments = " /x " + prdctId + " /Qn";
                uninstallProcess.Start();
                break;
            }
        }
       }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100