前言:在qt中获取CPU和主板唯一序列号,可以在程序构造函数中判断是否与windows中一致,不一致可以直接退出程序,防止程序daoyong。
一、获取电脑CPU唯一序列号
QString MainPage::get_cpu()
{QString cmd="wmic cpu get processorid";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 MainPage::get_main_board()
{QString cmd="wmic baseboard 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;
}
三、windows中获取cpu和主板序列号
首先win加R,输入cmd
输入wmic cpu get processorid,获取CPU唯一序列号。
输入wmic baseboard get serialnumber,获取主板唯一序列号。