52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
|
|
#include <QCoreApplication>
|
||
|
|
#include <QString>
|
||
|
|
#include <QFuture>
|
||
|
|
#include <QtConcurrent/QtConcurrent>
|
||
|
|
#include <windows.h>
|
||
|
|
#include <tlhelp32.h>
|
||
|
|
#include "CCThread.h"
|
||
|
|
#include "QProcess"
|
||
|
|
|
||
|
|
bool isProcessRunning(const QString &processName)
|
||
|
|
{
|
||
|
|
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||
|
|
if (hSnapshot == INVALID_HANDLE_VALUE)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
PROCESSENTRY32 pe;
|
||
|
|
pe.dwSize = sizeof(PROCESSENTRY32);
|
||
|
|
|
||
|
|
bool found = false;
|
||
|
|
if (Process32First(hSnapshot, &pe))
|
||
|
|
{
|
||
|
|
do
|
||
|
|
{
|
||
|
|
if (QString::fromWCharArray(reinterpret_cast<const wchar_t *>(pe.szExeFile)) == processName)
|
||
|
|
{
|
||
|
|
found = true;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
} while (Process32Next(hSnapshot, &pe));
|
||
|
|
}
|
||
|
|
|
||
|
|
CloseHandle(hSnapshot);
|
||
|
|
return found;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char *argv[]) {
|
||
|
|
static QSharedMemory *shareMem = new QSharedMemory("IPBS_NSSM"); //创建“SingleApp”的共享内存块
|
||
|
|
if (!shareMem->create(1))//创建大小1b的内存
|
||
|
|
{
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
QCoreApplication a(argc, argv);
|
||
|
|
while (true){
|
||
|
|
bool F = isProcessRunning("IPBS_Station.exe");
|
||
|
|
if(!F){
|
||
|
|
QProcess::startDetached("./IPBS_Station.exe");
|
||
|
|
}
|
||
|
|
Threading::Sleep(1000 * 1000 * 5);
|
||
|
|
}
|
||
|
|
return QCoreApplication::exec();
|
||
|
|
}
|