Uninstall software via the registry
I know this has been asked before, but bear with me. I have a utility that reads the Unistall location in the registry and then compares the results to a list of applications that need to be removed. 80% of the time this works, but the trick is that one of the items to be removed is the anti-virus (so it can be replaced with an AVG install). For a lot of the companies this doesn't work. Here is a snippet of how I'm getting the installed software:
const string Win32Loc = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
//const string Win32Loc = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\USerData\S-1-5-18";
const string Win64Loc = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
List<Application> apps = new List<Application>();
string location = bool64BitOs ? Win64Loc : Win32Loc;
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(location))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
apps.Add(new Application { DisplayName = sk.GetValue("DisplayName") == null ? "" : (string)sk.GetValue("DisplayName"), AppKey = skName });
}
}
}
The results look like this when written to a text file:
Name PowerDVD Key InstallShield_{6811CAA0-BF12-11D4-9EA1-0050BAE317E1}
Name ESC Home Page Plugin Key InstallShield_{E738A392-F690-4A9D-808E-7BAF80E0B398}
Name Intuit SiteBuilder Key Intuit SiteBuilder
Name Microsoft Visual J# 2.0 Redistributable Package Key Microsoft Visual J# 2.0 Redistributable Package
Name Norton AntiVirus Key NAV
Name Windows Live Essentials Key WinLiveSuite
Name Microsoft Visual C++ 2008 ATL Update kb973924 - x86 9.0.30729.4148 Key {002D9D5E-29BA-3E6D-9BC4-3D7D6DBC735C
So you'll see that SOME installs have th开发者_Python百科e key and some don't. What this means is that the 80% that work have the key for the MSIEXEC call, and the others fail. I'm playing with the Installer/UserData/UserXXXXX/Products but I don't get how to traverse for all users. In the dump I provided, Norton needs to go, but I can't see how to do it.
Any help would be greatly appreciated.
I agree with selbie's comment about using the "UninstallString" instead (although sometimes you won't have that either, but for MSI's use can just get the GUID and use msiexec /x {GUID}
).
Nevertheless, I would not recommend uninstalling Norton A/V products via this method. Because their uninstallers are crap and frequently leave behind many pieces of the software that should've been removed, Symantec provides a tool that actually gets the job done safely: the Norton Removal Tool. Highly recommended!
精彩评论