QT 如何判断电脑已安装某个软件
如何判断Windows电脑是否已经安装了某个软件?一般而言,通过安装包形式安装的软件,都会把卸载信息写入到注册表,本文正是通过读取注册表的方式来判断是否已安装了该款软件,详见下面代码:
#include <QCoreApplication>
#include <QSettings>
#include <QDebug>
bool is64bitOperatingSystem()
{
return sizeof(void *) == 8;
}
//如果返回不为空则表示已安装
QString HasInstall(const QString &softName)
{
QString header = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
bool is64bit = is64bitOperatingSystem();
if(is64bit){
header = "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
}
QSettings settings(header, QSettings::NativeFormat);
QStringList regGroups = settings.childGroups();
foreach (QString regItem, regGroups)
{
settings.beginGroup(regItem);
QString displayName = settings.value("DisplayName").toString();
QString installPath = settings.value("InstallLocation").toString();
QString uninstallString = settings.value("UninstallString").toString();
if(displayName.contains(softName))
{
QString filePath = installPath.replace("\\", "/");
return filePath;
}
settings.endGroup();
}
return "";
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
//
QString path = HasInstall("Chemiluminescence");
qDebug() << "path" << path;
//
return a.exec();
}