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("\r", ""); result = result.replace("\n", ""); 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"); }
发表评论