首页 > 解决方案 > 从应用程序和程序中删除注册表项

问题描述

我已经在这个主题上搜索了大约 2 个小时,我找到的所有资源都告诉我同样的事情。要从 Windows 10 应用程序和程序列表中删除注册表,请使用以下代码:

string InstallerRegLoc = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey homeKey = (Registry.LocalMachine).OpenSubKey(InstallerRegLoc, true);
RegistryKey appSubKey = homeKey.OpenSubKey("App name");
if (null != appSubKey) {
    homeKey.DeleteSubKey("App name");
}

我已经尝试过了,但它对我不起作用。正如我们在这里看到的,我在注册表中有程序“Key Stats”:

注册表应用

这一切都很好,但我不能从注册表中删除这个项目。这是我用来创建注册表的代码:

try {
    string guidText = "50038998-0755-41a2-8ae9-f9719f04c703";
    key = parent.OpenSubKey(guidText, true) ?? parent.CreateSubKey(guidText);

    if (key == null) {
        throw new Exception(String.Format("Unable to create uninstaller '{0}\\{1}'", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", guidText));
    }

    Assembly asm = GetType().Assembly;
    Version v = asm.GetName().Version;
    string exe = "\"" + asm.CodeBase.Substring(8).Replace("/", "\\\\") + "\"";

    key.SetValue("DisplayName", "Key Stats");
    key.SetValue("ApplicationVersion", v.ToString());
    key.SetValue("Publisher", "My Company");
    key.SetValue("DisplayIcon", exe);
    key.SetValue("DisplayVersion", v.ToString(2));
    key.SetValue("URLInfoAbout", "");
    key.SetValue("Contact", "");
    key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd"));
    key.SetValue("UninstallString", exe + " /uninstallprompt");
}
finally {
    if (key != null) {
        key.Close();
    }
}

我无法从注册表中删除该项目。有人可以帮我弄清楚为什么这不起作用吗?

标签: c#windowsregistryuninstallationregistrykey

解决方案


推荐阅读