VC判断进程是否存在

BOOL IsProcessExist(TCHAR* ptzProcessName)
{
	BOOL bRet = FALSE;
	HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if( INVALID_HANDLE_VALUE == hProcessSnap )
	{
		return FALSE;
	}

	PROCESSENTRY32 pe32 = { 0 };
	pe32.dwSize = sizeof( PROCESSENTRY32 );
	if( !Process32First( hProcessSnap, &pe32 ) )
	{
		CloseHandle( hProcessSnap ); 
		return FALSE;
	}

	do
	{
		if( !_tcscmp(pe32.szExeFile, ptzProcessName))
		{
			bRet = TRUE;
			break;
		}
	} while( Process32Next(hProcessSnap, &pe32));
	CloseHandle(hProcessSnap);
	
	return bRet;
}

你可能感兴趣的:(VC判断进程是否存在)