1.原因:某软件开机自启动很烦,搞一个程序干掉这个自启动的软件
2.QT代码
- main.cpp
#include "KillXXX.h"
#include <QtWidgets/QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);KillXXX k;return a.exec();
}
- KillXXX.h
#include <QtCore/QObject>class KillXXX : public QObject
{Q_OBJECTpublic:KillXXX(QObject*parent = nullptr);~KillXXX();void KillAppProcess();
private slots:void On_timeout();
private:QTimer* myTimer;int count;
};
- KillXXX.cpp
#include "KillXXX.h"
#include <QTimer>
#include <QProcess>
KillXXX::KillXXX(QObject*parent): QObject(parent)
{count = 0;myTimer = new QTimer(this);connect(myTimer, &QTimer::timeout, this, &KillXXX::On_timeout);myTimer->start(10000);
}KillXXX::~KillXXX()
{
}void KillXXX::KillAppProcess()
{QString processName = "进程名.exe"; // 要关闭的进程名称// 使用taskkill命令关闭进程QString command = "taskkill /F /IM " + processName ;QProcess::startDetached("cmd.exe", QStringList() << "/c" << command);
}void KillXXX::On_timeout()
{if (count >= 6){myTimer->stop();delete myTimer;myTimer = nullptr;this->deleteLater();}KillXXX::KillAppProcess();++count;
}
3.利用windeployqt打包这个.exe文件,加入开机自启动就可以啦
怎么打包一个软件(点击链接:https://blog.csdn.net/dfr110719/article/details/136992619)