一、环境介绍
QT版本: 5.12.6
环境: win10 64位
编译器: MinGW 32
二、功能介绍
通过wmic 命令获取CPU序列号、硬盘序列号、主板序列号、CPU名称等信息。
做软件加密、数据加密、软件1机1码绑定的场合比较实用。
WMIC扩展WMI(Windows Management Instrumentation,Windows管理工具) ,提供了从命令行接口和批命令脚本执行系统管理的支持。
wmic 命令很强大,在win10上系统上wmic命令被powershell的“ help Get-WmiObject ”代替,但是wmic 命令还是正常可以使用的。
这是powershell运行效果:
dos窗口运行wmic命令效果:
wmic 常用的命令介绍:
获取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 where index=0 get serialnumber
查看cpu详细信息: wmic cpu list brief
查看物理内存: wmic memphysical list brief
查看逻辑内存: wmic memlogical list brief
查看缓存内存: wmic memcache list brief
查看虚拟内存: wmic pagefile list brief
查看网卡: wmic nic list brief
关闭本地计算机: wmic process call create shutdown.exe
获取进程名称以及可执行路径: wmic process get name,executablepath
删除指定进程(根据进程名称):
wmic process where name=“qq.exe” call terminate
或者用
wmic process where name=“qq.exe” delete
删除指定进程(根据进程PID): wmic process where pid=“123” delete
创建新进程: wmic process call create “C:\Program Files\Tencent\QQ\QQ.exe”
三、软件运行效果
四、核心代码
4.1 widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QDebug>
#include <QProcess>
#include <windows.h>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();QString getWMIC(const QString &cmd);QString getCpuName();QString getCpuId();QString getBaseboardNum();QString getBiosNum();QString getDiskNum();
private slots:void on_pushButton_get_clicked();private:Ui::Widget *ui;
};
#endif // WIDGET_H
4.2 widget.cpp
#include "widget.h"
#include "ui_widget.h"/*
工程: video_file_encryption
日期: 2021-06-08
作者: DS小龙哥
环境: win10 QT5.12.6 MinGW32
功能: 获取CPU名称
*/
QString Widget::getCpuName()
{QString cmd="wmic cpu get name";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;
}/*
工程: video_file_encryption
日期: 2021-06-08
作者: DS小龙哥
环境: win10 QT5.12.6 MinGW32
功能: 获取CPU的ID
*/
QString Widget::getCpuId()
{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;
}/*
工程: video_file_encryption
日期: 2021-06-08
作者: DS小龙哥
环境: win10 QT5.12.6 MinGW32
功能: 查询主板序号
*/
QString Widget::getBaseboardNum()
{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;
}/*
工程: video_file_encryption
日期: 2021-06-08
作者: DS小龙哥
环境: win10 QT5.12.6 MinGW32
功能: 查询BIOS序号
*/
QString Widget::getBiosNum()
{QString cmd="wmic bios 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;
}/*
工程: video_file_encryption
日期: 2021-06-08
作者: DS小龙哥
环境: win10 QT5.12.6 MinGW32
功能: 查询硬盘序号
*/
QString Widget::getDiskNum()
{QString cmd="wmic diskdrive where index=0 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;
}Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);this->setWindowTitle("获取CPU信息");
}Widget::~Widget()
{delete ui;
}/*
工程: video_file_encryption
日期: 2021-06-08
作者: DS小龙哥
环境: win10 QT5.12.6 MinGW32
功能: 获取数据
*/
void Widget::on_pushButton_get_clicked()
{ui->lineEdit_cpu->setText(getCpuId());ui->lineEdit_bord->setText(getBaseboardNum());ui->lineEdit_cpu_name->setText(getCpuName());ui->lineEdit_bios->setText(getBiosNum());ui->lineEdit_disk->setText(getDiskNum());
}
4.3 ui界面