如何检查exe是否正在运行? [英] How to check whether an exe is running or not?

查看:105
本文介绍了如何检查exe是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查exe是否正在运行?

How to check whether an exe is running or not??

推荐答案

BOOL CBaseOperation::IsExeRunning(CString strExe)
{
	HANDLE hProcessSnap;
	BOOL bRet = FALSE;
	CString csProcessList = _T("");
	DWORD dwID = 0;
	PROCESSENTRY32 pe32;
	// Take a snapshot of all processes in the system
	hProcessSnap=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS,0);
	if(hProcessSnap == INVALID_HANDLE_VALUE)
	{
		bRet = FALSE;
		return bRet;
	}
	// Set the size of the structure before using it.
	pe32.dwSize =sizeof(PROCESSENTRY32);
	// Retrieve information about the first process,
	// and exit if unsuccessful
	if(!Process32First (hProcessSnap,&pe32))
	{
		CloseHandle( hProcessSnap );
		bRet = FALSE;
		return bRet;
	}
	// Now walk the snapshot of processes, and
	// display information about each process in turn
	while( Process32Next( hProcessSnap, &pe32 ))
	{
		if(strExe.Compare(pe32.szExeFile)==0)
		{
			return TRUE;
		}
	}
	CloseHandle( hProcessSnap );
	return bRet;
}


bool isRunning = Process .GetProcessesByName("test").FirstOrDefault(p => p.MainModule.FileName.StartsWith(@"c:\ loc1"))!= default(Process);
bool isRunning = Process.GetProcessesByName("test").FirstOrDefault(p => p.MainModule.FileName.StartsWith(@"c:\loc1")) != default(Process);


这篇关于如何检查exe是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆