首页 > 编程语言 > 详细

判断当前进程是否已经打开C++

时间:2020-05-23 10:37:11      阅读:64      评论:0      收藏:0      [点我收藏+]
int foundProcessByName(const char *filename)
{
	int foundProcessTimes = 0;
	HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
	PROCESSENTRY32 pEntry;
	pEntry.dwSize = sizeof(pEntry);
	BOOL hRes = Process32First(hSnapShot, &pEntry);
	while (hRes)
	{
		_bstr_t b(pEntry.szExeFile);
		const char* c = b;
		if (strcmp(c, filename) == 0)
		{
			std::wstring ws(pEntry.szExeFile);
			std::string test(ws.begin(), ws.end());
			//qDebug() << QString("Found Process %1").arg(QString::fromStdString(test));
			foundProcessTimes++;
		}
		hRes = Process32Next(hSnapShot, &pEntry);
	}
	CloseHandle(hSnapShot);
	return foundProcessTimes;
}

if(foundProcessByName("ThreadName") > 1)
{
  //进程已打开。      
}

  

判断当前进程是否已经打开C++

原文:https://www.cnblogs.com/foreversdf/p/12900519.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!