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, ...)
Prefer 32-bitoption inProject->Properties->Build?prefer 32-bit. The option is also grayed out and I can't click itp_nameis, I assume it's thenamestring you're passing to the method. -- Not sure why you haveGUID = 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 thekeyNamestring. Sometimes the same GUID is repeated insideUninstallString(since it's passed to the installer), but you'd have to extract it. Anyway, it's the same string, so no need to.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 :)