我希望通过注册表中的应用程序名称获取应用程序卸载路径。
代码:
QString Test::getAppUninstallPath(QString name)
{
QString uninstallLocation;
QStringList allCurrentUserKeys;
QSettings registryKeyCurrentUser("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
allCurrentUserKeys = registryKeyCurrentUser.allKeys();
for (QString key : allCurrentUserKeys) {
if (key.contains("DisplayName")) {
if (registryKeyCurrentUser.value(key).toString() == name) {
uninstallLocation = registryKeyCurrentUser.value("UninstallString").toString();
}
}
}
return uninstallLocation;
}
它什么都不返回。如何获取应用程序的卸载路径?感谢。
答案 0 :(得分:0)
感谢 hskoglund 。因为我处理的是层次结构/嵌套键,所以我应该使用beginGroup()
/ endGroup()
。
<强>代码:强>
QString uninstallLocation;
QSettings registryKeyLM("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", QSettings::NativeFormat);
auto allGroups = registryKeyLM.childGroups();
for (auto group : allGroups)
{
registryKeyLM.beginGroup(group);
for (auto key : registryKeyLM.childKeys())
if ("DisplayName" == key)
if (registryKeyLM.value(key) == name)
uninstallLocation = registryKeyLM.value("UninstallString").toString();
registryKeyLM.endGroup();
}
return uninstallLocation;