Qt 判断系统是否安装VC运行库

时间:2020-12-16 17:43:51
static bool HasIntStallVC2015(){
    QString header = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
    QSettings reg(header,QSettings::NativeFormat);
    QMap<QString,QString> m_data;
    QStringList sum = reg.allKeys();
    for(int m  = 0 ; m < sum.size();++m){
        QString id = sum.at(m);
        int end = id.indexOf("}");
        if(end > 0){
            id = id.mid(0,end+1);

            if(!m_data.keys().contains(id)){
                QSettings gt(header + id,QSettings::NativeFormat);
                QString name = gt.value("DisplayName").toString();
                if(!name.isEmpty() && name.contains("Microsoft Visual C++")){
                    m_data[id] = name;
                }

            }

        }
    }

  QMap<QString,QString>::const_iterator it = m_data.constBegin();
  while (it != m_data.constEnd()) {
      if(it.value().contains("Microsoft Visual C++ 2015 Redistributable (x64)"))
          return true;
      ++it;

  }
  return false;
}