qt判断指定进程是否处于运行状态

#include
#include

判断进程是否处于运行状态
bool CProcessManager::isProcessRunning(QString processName)
{
bool ret = false;
HANDLE proHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if ((HANDLE)-1 == proHandle)
{
return false;
}

//进程信息
PROCESSENTRY32 pInfo;
pInfo.dwSize = sizeof(PROCESSENTRY32);

//获得第一个进程
BOOL bResult = Process32First(proHandle, &pInfo);
if (!bResult)
{
	return false;
}

QString curProcessName;  //proUrl, proPid;
while (bResult)
{
	curProcessName = QString("%1").arg(QString::fromUtf16(reinterpret_cast(pInfo.szExeFile)));

	if (curProcessName == processName)
	{
		ret = true;
		break;
	}

	//获得下一个进程
	bResult = Process32Next(proHandle, &pInfo);
}

//关闭句柄
CloseHandle(proHandle);
return ret;

}

你可能感兴趣的:(qt判断指定进程是否处于运行状态)