通过registry卸载软件

我知道这已经被问过,但忍受着我。 我有一个实用程序读取registry中的Unistall位置,然后将结果与需要删除的应用程序列表进行比较。 80%的工作时间,但诀窍是,要删除的项目之一是反病毒(所以可以用AVG安装replace)。 对于很多公司来说这是行不通的。 这里是我得到安装的软件的一个片段:

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 }); } } } 

写入文本文件时,结果如下所示:


名称PowerDVD密钥InstallShield_ {6811CAA0-BF12-11D4-9EA1-0050BAE317E1}

名称ESC主页插件密钥InstallShield_ {E738A392-F690-4A9D-808E-7BAF80E0B398}

名称Intuit SiteBuilder关键Intuit SiteBuilder

名称Microsoft Visual J#2.0可再发行组件包密钥Microsoft Visual J#2.0可再发行组件包

名称Norton AntiVirus Key NAV

名称Windows Live Essentials Key WinLiveSuite

名称Microsoft Visual C ++ 2008 ATL更新kb973924 – x 86 9.0.30729.4148密钥{002D9D5E-29BA-3E6D-9BC4-3D7D6DBC735C


所以你会看到一些安装有密钥,有些则没有。 这意味着80%的工作是MSIEXEC调用的关键,其他人失败了。 我正在玩Installer / UserData / UserXXXXX / Products,但我不知道如何遍历所有用户。 在我提供的转储中,诺顿需要去,但是我看不到如何去做。

任何帮助将不胜感激。

我同意selbie有关使用“UninstallString”的意见(尽管有时候你也不会这样做,但是对于MSI的使用,只能获取GUID并使用msiexec /x {GUID} )。

不过,我不建议通过这种方法卸载Norton A / V产品。 由于他们的卸载程序是废话,经常留下许多应该删除的软件,赛门铁克提供了一个工具,安全地完成工作: 诺顿删除工具 。 强烈推荐!