zoukankan      html  css  js  c++  java
  • Qt获取CPU编号和硬盘序列号

    windows下执行命令除了用cmd之外,还有个东西叫WMIC,非常强大,可以通过他获取很多信息,包括硬件信息。

    QString frmMain::getWMIC(const QString &cmd)
    {
        //获取cpu名称:wmic cpu get Name
        //获取cpu核心数:wmic cpu get NumberOfCores
        //获取cpu线程数:wmic cpu get NumberOfLogicalProcessors
        //查询cpu序列号:wmic cpu get processorid
        //查询主板序列号:wmic baseboard get serialnumber
        //查询BIOS序列号:wmic bios get serialnumber
        //查看硬盘:wmic diskdrive get serialnumber
        QProcess p;
        p.start(cmd);
        p.waitForFinished();
        QString result = QString::fromLocal8Bit(p.readAllStandardOutput());
        QStringList list = cmd.split(" ");
        result = result.remove(list.last(), Qt::CaseInsensitive);
        result = result.replace("
    ", "");
        result = result.replace("
    ", "");
        result = result.simplified();
        return result;
    }
    
    QString frmMain::getCpuName()
    {
        return getWMIC("wmic cpu get name");
    }
    
    QString frmMain::getCpuId()
    {
        return getWMIC("wmic cpu get processorid");
    }
    
    QString frmMain::getDiskNum()
    {
        return getWMIC("wmic diskdrive where index=0 get serialnumber");
    }
    

      

  • 相关阅读:
    jenkins持续集成
    对pm2对研究
    模板⽅法模式
    python configparser模块
    Python正则表达式
    Python读写文件之换行符
    Python字符串
    Python字典
    Python列表
    爬虫 urllib,requests,lxml,bs4 小结
  • 原文地址:https://www.cnblogs.com/feiyangqingyun/p/10443149.html
Copyright © 2011-2022 走看看