Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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....

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.
 
Share this answer
 
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;
            }
        }
       }
 
Share this answer
 
Comments
Özlem AKALIN 25-Sep-21 7:28am    
Hi, i got an error at "string prdctId = uninstlString.Substring((uninstlString.IndexOf("{")));" line. The error is " System.ArgumentOutOfRangeException: 'StartIndex cannot be less than zero. ' ". uninstlString variable contains uninstall.exe directory; not product id of the product.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900