0

I want to uninstall some app programmatically. I'm searching in this path in win registry:

\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

the code for searching and uninstalling is the following:

public string UninstallCMD;

    public bool SearchApp(string p_name)
            {
                string displayName;
                RegistryKey key;
    
    key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
                foreach (String keyName in key.GetSubKeyNames())
                { 
                    RegistryKey subkey = key.OpenSubKey(keyName);
                    displayName = subkey.GetValue("DisplayName") as string;
                
                    if (p_name.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
                    {
                        UninstallCMD = subkey.GetValue("UninstallString") as string;
                        return true;
                    }
                }
    }

My problem is that not all the key were read. The key that I want to be read is {56DDDFB8-7F79-4480-89D5-25E1F52AB28F} but is ignored like the other in { } (in this image you can see the key ignored)

The key without { } were read normally (i.e. 7-zip, VLC media player, ...)

4
  • What is the bitness of your application? 32bit or 64bit? Did you deselect the Prefer 32-bit option in Project->Properties->Build? Commented Mar 20, 2021 at 17:41
  • @Jimi It's a 64bit application and I have deselected prefer 32-bit. The option is also grayed out and I can't click it Commented Mar 20, 2021 at 20:35
  • All right. Now, I don't know what that p_name is, I assume it's the name string you're passing to the method. -- Not sure why you have GUID = subkey.GetValue("UninstallString") as string;, that's not the GUID, it's the string you need to Shell out to start the uninstall procedure. Those GUIDs you're referring to are returned in the keyName string. Sometimes the same GUID is repeated inside UninstallString (since it's passed to the installer), but you'd have to extract it. Anyway, it's the same string, so no need to. Commented Mar 20, 2021 at 23:31
  • Yep. p_name == name. I've corrected the code. I pass the name of application to unistall. I want to search in registry for that application. Then I take the string to start the uninstall procedure. I've also edited some line to make code more clear :) Commented Mar 21, 2021 at 9:05

1 Answer 1

0

I don't know why but after recompiling solution, everything work fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.