How to uninstall an application programmatically

I tried this , this, to remove the application programmatically. I do not get any errors or exceptions, but the application is not removed from my computer. Please see trial code also

public static string GetUninstallCommandFor(string productDisplayName)
{
    RegistryKey localMachine = Registry.LocalMachine;
    string productsRoot = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products";
    RegistryKey products = localMachine.OpenSubKey(productsRoot);
    string[] productFolders = products.GetSubKeyNames();

    foreach (string p in productFolders)
    {
        RegistryKey installProperties = products.OpenSubKey(p + @"\InstallProperties");
        if (installProperties != null)
        {
            string displayName = (string)installProperties.GetValue("DisplayName");
            if ((displayName != null) && (displayName.Contains(productDisplayName)))
            {
                string uninstallCommand =(string)installProperties.GetValue("UninstallString");

                return uninstallCommand;
            }
        }
    }

    return "";        
}

Please help me uninstall the application programmatically using C #.

0
source share
1 answer

The above routine will return a string, assuming a match is found that might look like this:

MsiExec.exe/X{02DA0248-DB55-44A7-8DC6-DBA573AEEA94}

You should take this and run as a process:

System.Diagnostics.Process.Start(uninstallString);

, msiexec, , . msiexec, /q uninstallString ( /).

: Windows 3.0 , /quiet / . , /qn ( ). @JRO , !

+3

Source: https://habr.com/ru/post/1760305/


All Articles