c# - 从应用程序和程序中删除注册表项
问题描述
我已经在这个主题上搜索了大约 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();
}
}
我无法从注册表中删除该项目。有人可以帮我弄清楚为什么这不起作用吗?
解决方案
推荐阅读
- python - 虚拟 CAN 总线模拟器在 Ubuntu 上不起作用
- python - 在没有 IndexError 的情况下在循环内递增 Python 循环计数器:列表索引超出范围
- java - 如何将文本输入转换为 java.time.LocalDateTime?
- javascript - Ionic Router 何时触发渲染(包括屏幕外路由)?
- java - 在 Java 11 中声明不可变的linkedhashmap 的任何方式
- javascript - Javascript遍历嵌套对象并返回转换和重命名的对象数组
- python - 通过数学运算从 n 中获得 n 乘以 1
- c# - Linq join() - 连接两个实体并选择一个
- tensorflow-lite - 如何在安卓应用中使用 ssd_mobilenet_v2_mnasfpn_coco
- linux - 严格使用 sed 格式化输入文本文件