参考:
查询windows系统下某程序是否已安装(注册表方式)---Qt_注册表 查看 exe-CSDN博客
Qt 操作注册表 - 十一的杂文录 - 博客园 (cnblogs.com)
Qt_32位程序在64位系统下读取64位注册表_众智日照读取注册表失败-CSDN博客
环境:
Windows系统:64位
Qt程序:32位
代码:
void read_from_regedit(QString path,QStringList &name_list,QStringList &path_list,bool is_32)
{
QSettings *settings;
if(is_32){
settings=new QSettings(path,QSettings::Registry64Format);
}
else{
settings=new QSettings(path,QSettings::NativeFormat);
}
QStringList list=settings->childGroups();
for(int i=0;i<list.count();++i)
{
settings->beginGroup(list.at(i));
name_list<<settings->value("DisplayName").toString();
path_list<<settings->value("DisplayIcon").toString();
settings->endGroup();
}
delete settings;
}
void search_app(QString name)
{
QStringList name_list;
QStringList path_list;
read_from_regedit("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",name_list,path_list,true);
read_from_regedit("HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall",name_list,path_list,false);
for(int i=0;i<name_list.count();++i)
{
if(name_list.at(i)==name){
qDebug()<<path_list.at(i);
qDebug()<<i;
}
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
search_app(QString("Notepad++ (64-bit x64)"));
search_app(QString("微信"));
return a.exec();
}
?关键点:
if(is_32){
settings=new QSettings(path,QSettings::Registry64Format);
}
else{
settings=new QSettings(path,QSettings::NativeFormat);
}